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)