DEV Community

Cover image for DIY Telegram-Controlled ESP32 Security Cam
A C
A C

Posted on

DIY Telegram-Controlled ESP32 Security Cam

๐Ÿ›ก๏ธ 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

ESP32-CAM

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.

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.

Connections


๐Ÿค– 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
Enter fullscreen mode Exit fullscreen mode

Only messages from the authorized CHAT_ID (set in code) are processed. Others are politely ignored.

bot


๐Ÿงฉ Code Highlights

  • Camera & Wi-Fi initialized via esp_camera_init() and WiFi.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?

  1. Clone the repo and install these libraries:
    • UniversalTelegramBot, ArduinoJson, esp_camera
  2. Update the sketch:
    • Set your WiFi SSID, password, Telegram BOT token, and your personal CHAT_ID
  3. Upload via Arduino IDE with GPIO0 bridged to GND
  4. 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

Hackster.io project page


Top comments (0)