๐ก๏ธ Smart Home Security with ESP32โCAM & Telegram Bot
A DIY surveillance project that uses an ESP32โCAM, a PIR motion sensor, and a Telegram bot to create a smart, phone-controlled home security system.
Inspired by ESP32โCAM and Telegram bot integrations across the Arduino and maker community.
๐งฉ Overview
This project transforms an ESP32โCAM into a fully functional mini security systemโno keypads, no app infractions, no hassle. Users can:
- ๐ธ Receive instant photos via Telegram when motion is detected.
- ๐ซต Request live snapshots on demand.
- ๐ก Control the onboard LED or toggle the PIR sensor.
- ๐ Arm or disarm the motion detection remotely.
All managed through easy-to-remember Telegram bot commands. The core functionality is implemented using UniversalTelegramBot, esp_camera, and standard Arduino wiring.
๐ GitHub Repository
๐ Hackster Project
๐ง Hardware Requirements
- ESP32โCAM (AIโThinker) with OV2640 camera module
- HCโSR501 PIR motion sensor, powered at 3.3โฏV
- USBโtoโTTL serial adapter (e.g., PL2303)
- Jumper cables, breadboard, and power source
๐ง Wiring & Setup
Connection between the Esp32Cam and the USB to serial cable
| ESP32-CAM | USB-to-Serial Cable |
|---|---|
| 5V | Red Cable |
| GPIO3 | Green Cable |
| GPIO1 | White Cable |
| GND | Black Cable |
โ ๏ธ Connect GPIO 0 and GND ports with DuPont cable as following to load the code.
| ESP32-CAM | ESP32-CAM |
|---|---|
| GND | GPIO0 |
โ ๏ธ Remember to disconnect the GPIO 0 and GND ports after loading the code and press the reset button on the Esp to execute the code.
Connection between Esp32Cam and PIR.
| ESP32-CAM | HC-SR501 Human Infrared Sensor |
|---|---|
| 3.3V | VCC |
| GND | GND |
| GPIO 13 | DATA |
โ ๏ธ If ESP32 CAM takes pictures frequently or never take a picture, adjust the rotary buttons on the HC-SR501 Human Infrared Sensor.
๐ค Telegram Bot Commands
Interact with the ESP via Telegram commands:
/start โ Get help menu
/take_photo โ Request instant snapshot
/security_on โ Arm motion detection
/security_off โ Disarm motion detection
/led_on โ Turn onboard LED ON
/led_off โ Turn onboard LED OFF
/state โ Check current LED & armed state
Only messages from the authorized CHAT_ID (set in code) are processed. Others are politely ignored.
๐งฉ Code Highlights
-
Camera & Wi-Fi initialized via
esp_camera_init()andWiFi.begin() - Motion loop: If armed and motion is detected โ take photo โ send via Telegram
-
Telegram handler: Parses messages using
UniversalTelegramBot, performs requested action -
Secure communication with Telegram via
WiFiClientSecure
๐ Ready to Get Started?
- Clone the repo and install these libraries:
-
UniversalTelegramBot,ArduinoJson,esp_camera
-
- Update the sketch:
- Set your WiFi SSID, password, Telegram BOT token, and your personal CHAT_ID
- Upload via Arduino IDE with GPIO0 bridged to GND
- Reboot and interact via Telegram!
๐ค Possible Improvements
- ๐พ Store photos on microSD
- ๐ก Add time-based auto arming
- ๐ง Use face recognition for better filtering
- ๐ Add multi-platform alerting
๐ Project links
If you find it useful, give it a โญ on GitHub! Link to repository: Github




Top comments (0)