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)