HC-SR501 + ESP-32 + Telegram equals a motion sensor alarm! Also serves as a good introduction to the ESP-IDF, the official development framework for the ESP-32. The HC-SR501 detects the motion, the ESP-32 sends an HTTP request to the Telegram API which then relays the message to you.
Made with ESP-IDF and PlatformIO.
HC-SR501 | ESP-32 |
---|---|
GND | GND |
OUT | G26 |
VCC | 5V |
If you want HC-SR501 - OUT
to connect to another GPIO. Change the variable SENSOR_GPIO
with with one of these values https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html#_CPPv410gpio_num_t.
Before using, you should change the following variables:
ESP_WIFI_SSID
: WiFi SSID.ESP_WIFI_PASS
: WiFi password.TG_AUTH_TOKEN
: Telegram bot auth token. See https://core.telegram.org/bots/api#authorizing-your-bot.TG_TARGET_CHAT_ID
: Telegram chat id where you want the alerts to be sent. If you don't know how to get the chat id, start the bot @RawDataBot and use the value inmessage.chat.id
.
- Urlencoding library (
include/urlencode.h
): https://github.com/harkaitz/c-urlencode.