October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Bettesworth Construction
Arduino

Build an ESP32-CAM Motion Camera That Sends Photos to Telegram

Learn how to build a DIY ESP32-CAM motion-notification camera that captures PIR-triggered photos and sends them to Telegram, with safe wiring and troubleshooting guidance.

By Bettesworth Construction Team 8 min read
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Yes—you can use an AI-Thinker ESP32-CAM, a PIR sensor, and a Telegram bot to create a low-cost motion-notification camera. When the PIR detects movement, the ESP32-CAM captures a JPEG image and uploads it to a private Telegram chat over HTTPS. The device can also respond to commands such as /photo, /flash, and /status.

This is a DIY notification camera, not a professional surveillance system. It depends on stable power, Wi-Fi, the internet, and Telegram, and a PIR sensor detects changes in infrared radiation—not people specifically.

As an Amazon Associate I earn from qualifying purchases.

How the project works

PIR sensor
    │ motion signal
    ▼
ESP32-CAM ── Wi-Fi ── HTTPS ── Telegram Bot API ── private chat
    │
    └── OV2640 camera
  1. The PIR sensor output changes to HIGH.
  2. The ESP32-CAM recognizes a new motion event rather than repeatedly reacting while the signal remains high.
  3. The OV2640 camera captures a JPEG frame.
  4. The firmware sends the image with Telegram’s sendPhoto method.
  5. A cooldown prevents a stream of duplicate alerts.
  6. After the PIR output returns low, the system is rearmed.

A PIR sensor can be triggered by a person, pet, moving curtain, sunlight, heater, or warm airflow. A stationary person may not continue triggering it after the initial movement.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Parts and prerequisites

Part Purpose and selection advice
AI-Thinker ESP32-CAM Microcontroller, Wi-Fi radio, and camera interface. Confirm the AI-Thinker pin map and OV2640-compatible camera.
HC-SR501-style PIR module Digital motion trigger. Use a module with an output compatible with 3.3 V ESP32 GPIO.
Regulated 5 V supply Power for the ESP32-CAM and PIR. Choose a supply with comfortable current headroom.
USB-to-serial adapter or ESP32-CAM-MB Uploads firmware. The UART logic must be 3.3 V.
Jumper wires Keep power and ground wires short to reduce voltage drop and noise.
Optional enclosure and mount Protects the board and fixes the camera’s viewing angle.

The AI-Thinker specification lists an OV2640 camera interface, 4 MB external PSRAM, 5 V input, a GPIO4 flash LED, and approximate consumption of 180 mA at 5 V with the flash off and 310 mA with the flash at maximum. See the AI-Thinker ESP32-CAM specification.

#1 Best Overall
Hosyond 2Pcs ESP32-CAM Wireless WiFi+Bluetooth Development Board with OV Camera Module Compatible with Arduino
  • ESP32CAM is based on ESP32 chip and OV camera module, use low-power dual-core 32-bit CPU, which can be used as an application processor.
  • The main frequency is up to 240MHz, and the computing power is up to 600 DMIPS.
  • Built-in 520 KB SRAM , external 8MB PSRAM ,support UART/SPI/I2C/PWM/ADC/DAC and other interfaces;Support picture wireless upload, TF card, multiple sleep modes, STA/AP/STA+AP working mode, secondary development.
  • It is an ideal solution for IoT applications. The ESP-32CAM comes in a DIP package that plugs directly into the backplane for rapid production.
  • ESP-32CAM can be widely used in various IoT applications. Suitable for home smart devices, industrial wireless control, wireless monitoring, QR wireless identification, wireless positioning system signals, etc.

Power is the first reliability requirement

Do not power the board from a weak 3.3 V output on a USB-to-serial adapter. Camera capture, Wi-Fi transmission, and the flash LED can create current transients that cause voltage drops.

Use a stable regulated 5 V source and connect grounds together. Brownouts commonly appear as repeated resets, Brownout detector was triggered, failed camera initialization, Wi-Fi disconnects, or incomplete images. A stronger supply, shorter wires, reduced frame size, and disabling the flash are better fixes than disabling brownout protection.

Wiring the ESP32-CAM and PIR

For a baseline build that does not use a microSD card:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
PIR VCC  → ESP32-CAM 5V
PIR GND  → ESP32-CAM GND
PIR OUT  → ESP32-CAM GPIO13

Check the PIR output voltage before connecting it. The ESP32 uses 3.3 V GPIO logic. If your sensor produces a higher voltage, use a suitable level shifter or voltage-divider arrangement.

Common HC-SR501 boards have adjustable sensitivity and delay controls. They also need a warm-up period after power-up. Their retrigger setting affects whether the output stays high when movement continues.

GPIO13 is associated with the microSD interface on the AI-Thinker board. The wiring above is therefore appropriate only when microSD is not being used and the board’s boot behavior has been checked. GPIO12 and GPIO13 should not be treated as universally free pins.

Uploading firmware

USB-serial GND → ESP32-CAM GND
USB-serial TX  → ESP32-CAM U0R / GPIO3
USB-serial RX  → ESP32-CAM U0T / GPIO1
USB-serial 5V  → ESP32-CAM 5V, only if adequate current is available
GPIO0         → GND during flashing

TX and RX cross over: adapter TX goes to board RX, and adapter RX goes to board TX. Connect GPIO0 to GND only while entering download mode. After uploading:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Disconnect GPIO0 from GND.
  2. Reset or power-cycle the board.
  3. Open the serial monitor at the baud rate used by the sketch, commonly 115200.

Create and authorize the Telegram bot

  1. Open Telegram and start a conversation with @BotFather.
  2. Send /newbot.
  3. Choose a display name.
  4. Choose a unique username ending in bot.
  5. Copy the generated token.
  6. Start a conversation with your new bot and press Start.

The token is a password. Do not publish it in screenshots, repositories, tutorials, or forum posts. Telegram documents the HTTPS API format as:

https://api.telegram.org/bot<TOKEN>/<METHOD>

Find the numeric chat ID

Send a message to your bot, then open this URL in a browser after replacing TOKEN:

https://api.telegram.org/bot<TOKEN>/getUpdates

Find the value at message.chat.id. Group chat IDs may be negative, so store the value in a type that can represent a negative number. If the response is empty, confirm that you pressed Start and sent a new message.

Telegram’s getUpdates method uses long polling. The firmware should advance the update offset so the same command is not processed repeatedly. Polling also cannot be used while an outgoing webhook is configured. See the Telegram Bot API documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
FORIOT 3Pcs ESP32-S3-CAM Development Board with OV3660 Camera, ESP32-S3-WROOM N16R8 Module with Dual Type-C Interface Support Wi-Fi and Bluetooth MCU Microcontroller for IoT, DIY and AI Project
  • Dual-core processor: The ESP32 module is based on the powerful ESP32-S3-WROOM N16R8 module and is equipped with a dual-core 32-bit LX7 processor. Its excellent AI computing performance, real-time processing capabilities, and low power consumption make it ideal for image recognition, edge AI, and complex IoT applications
  • Integrated 2-megapixel OV3660 camera: Built-in OV3660 camera to capture clear images and stream video in real time. Perfect for smart surveillance, face recognition, and AI-based computer vision projects. It is the preferred solution for DIY makers and professionals to build camera-enabled IoT systems
  • Dual Type-C ports for OTG and serial debugging: Designed with two USB Type-C interfaces - one supports USB OTG for host/device functions, and the other provides TTL serial for easy programming and debugging
  • Shared antenna: Supports IEEE 802.11b/g/n Wi-Fi (2.4GHz) and Bluetooth 5 (LE and Mesh), using shared antennas to optimize wireless performance. Enhanced 2 Mbps PHY and long-distance communication (Coded PHY) ensure stable multitasking in harsh environments
  • Multi-scenario applications: The ESP32 S3 development board maintains high stability even at high temperatures, making it ideal for industrial environments, educational purposes, and AI-driven projects. It is a versatile choice for robots, smart devices, and machine vision in lab or field applications

Install the Arduino software

  1. Install the current Arduino IDE from Arduino’s software page.
  2. Open Boards Manager and install Espressif’s ESP32 board package.
  3. Select the AI-Thinker ESP32-CAM board profile if it is available in the installed package.
  4. Install UniversalTelegramBot and any JSON dependency requested by that library version.
  5. Select the correct serial port.
  6. Upload with GPIO0 connected to GND, then remove that connection and reset.

The camera component is included with Arduino-ESP32; Espressif says that a separate camera installation is not required in Arduino IDE. Higher-than-CIF JPEG configurations generally require PSRAM. The Espressif camera documentation also recommends JPEG for Wi-Fi camera applications.

For PlatformIO, the commonly used board identifier is:

[env:esp32cam]
platform = espressif32
board = esp32cam
framework = arduino

PlatformIO documents this board as esp32cam in its AI-Thinker ESP32-CAM board page.

Configure the camera

The firmware must use the AI-Thinker camera pin map, JPEG pixel format, and a frame size appropriate for the available memory. A practical starting configuration is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
if (psramFound()) {
  config.frame_size = FRAMESIZE_SVGA;
  config.jpeg_quality = 12;
  config.fb_count = 2;
} else {
  config.frame_size = FRAMESIZE_CIF;
  config.jpeg_quality = 15;
  config.fb_count = 1;
}

In the ESP32 camera driver, lower JPEG-quality numbers generally produce better quality and larger files. Higher resolution also increases memory use, upload time, and the chance of power or timeout problems. Begin with VGA or SVGA and increase the size only after reliable delivery is established.

The OV2640 can be listed at up to 1600 × 1200, but that is a sensor capability—not a guarantee that maximum-size images will be practical to upload reliably through Telegram.

Send a photo through Telegram

Telegram’s photo endpoint is:

POST https://api.telegram.org/bot<TOKEN>/sendPhoto

The request needs a target chat_id and the JPEG as photo, optionally with a caption. There are two implementation paths.

Option 1: UniversalTelegramBot

The Universal-Arduino-Telegram-Bot library reduces the amount of multipart-upload and command-polling code you must write. Its repository includes ESP32-CAM photo examples.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the library’s ESP32-CAM example as the API reference for the version installed in your project. Library signatures, ArduinoJson dependencies, and TLS examples can change; do not assume an old example is compatible with every current board package.

Option 2: Direct HTTPS multipart upload

A direct request gives more control but requires correctly constructing a multipart/form-data body, including boundaries, content length, the chat_id field, and the JPEG field. It also requires careful TLS handling and timeout recovery. This is better suited to readers who need to minimize dependencies.

Do not make the device appear secure merely by using HTTPS. HTTPS protects the network connection to Telegram; the bot token, authorized chat IDs, physical device, and cloud-service dependency still require protection.

Rank #3
FORIOT 3Pcs OV2640 Camera Module, ESP32-CAM ESP32 Camera 160° Wide-Angle Lens 2 Megapixel Sensor I2C Support JPEG RGOV2640 Camera ModuleB YUV for ESP32 MCU Camera
  • 【160° Wide-angle Lens】 This ov2640 AC OV2640 camera module features a 160° viewing angle and 2 megapixels, providing you with an open view. Ideal for esp32 cam, ESP32_camera, esp32-cam, and esp32 camera module projects.
  • 【High-Quality Image】 The OmniVision image sensor applies unique sensor technology to improve image quality by reducing or eliminating optical or electronic defects such as fixed-pattern noise, tailing, and floating scatter, obtaining clear and stable color images.
  • 【Compact & Low Voltage for ESP32 MCU】 The small size and low operating voltage of this OV2640 camera module provide all required functions for a microcontroller-based UXGA camera and image processor, making it perfect for esp32 camera module applications.
  • 【Flexible Output & SCCB/I2C Control】 Controlled via the SCCB bus (compatible with I2C), the OV2640 camera can output 10-bit sampled data at various resolutions in whole frame, sub-sampling, and windowing. It supports JPEG, RGB, and YUV formats for ESP32-CAM.
  • 【Full Image Processing Control】 The lens delivers UXGA images up to 15 fps. Users have full control over image quality, data format, and transmission method. All image processing functions including gamma curve, white balance, saturation, chroma, etc., can be programmed through the SCCB interface.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use edge-triggered PIR logic

A naïve loop sends a photo on every pass while the PIR output is high. Instead, trigger only when the signal changes from low to high and add a cooldown:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
bool motionActive = false;
unsigned long lastAlert = 0;
const unsigned long alertCooldown = 15000;

void loop() {
  bool motion = digitalRead(PIR_PIN) == HIGH;

  if (motion && !motionActive) {
    motionActive = true;

    if (millis() - lastAlert >= alertCooldown) {
      captureAndSendPhoto();
      lastAlert = millis();
    }
  }

  if (!motion) {
    motionActive = false;
  }

  processTelegramCommands();
}

A robust implementation should also include a limited retry count, Wi-Fi reconnection, camera-capture failure handling, an HTTPS timeout, and a lockout while motion remains active. Add a PIR warm-up delay after boot before enabling alerts.

Useful bot commands

  • /start — display the available commands.
  • /photo — capture and send a photo.
  • /flash — toggle the onboard flash LED on GPIO4.
  • /status — report Wi-Fi and sensor state.
  • /reboot — restart the ESP32-CAM.

Only accept commands from an allowlisted chat ID. Reject other users before executing any action:

if (chat_id != CHAT_ID) {
  bot.sendMessage(chat_id, "Unauthorized user", "");
  continue;
}

For a private installation, it is safer not to reveal whether the device exists to unauthorized users; silently ignoring unknown chats may be preferable to sending an acknowledgment.

Test in stages

  1. Confirm clean serial output and a stable boot.
  2. Confirm Wi-Fi connection and log the assigned address.
  3. Run the official CameraWebServer example before adding Telegram.
  4. Test the bot token with getMe.
  5. Send a plain Telegram text message.
  6. Test manual /photo.
  7. Test one PIR-triggered alert.
  8. Walk repeatedly through the detection area and verify cooldown behavior.
  9. Test recovery after a Wi-Fi interruption and a restart.
  10. Test with the flash enabled only after the basic system is stable.

Troubleshooting

Camera initialization fails

Verify the AI-Thinker camera model and pin map, reseat the ribbon cable, confirm PSRAM detection, reduce the frame size, and use a stable 5 V source. Test the official CameraWebServer example independently.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The board resets during capture or upload

This is usually a power or voltage-drop problem. Improve the 5 V supply, shorten the wires, avoid a weak serial-adapter output, disable the flash, and reduce the image size. Do not permanently disable brownout detection as a substitute for correcting the supply.

Telegram receives no image

Check the token with getMe, retrieve the actual chat ID with getUpdates, press Start on the bot, and verify that the bot belongs to the target group. Log the HTTP status and response body. Reduce image size and confirm that only polling or webhook delivery—not both—is configured.

Several images arrive for one movement

Use rising-edge detection, wait for the PIR signal to return low, add a cooldown, and adjust the sensor’s delay and retrigger controls.

The PIR triggers randomly

Allow its warm-up period, reduce sensitivity, shield it from direct sunlight and HVAC vents, improve the power supply, and add software cooldown. PIR detects thermal changes, so it cannot distinguish an intruder from every other warm moving object.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Security, privacy, and installation limits

  • Keep the bot token out of source-control history and public documentation.
  • Allowlist the intended chat ID.
  • Use certificate validation where the selected HTTPS library supports it; avoid treating setInsecure() as a finished security solution.
  • Do not expose the camera’s local web interface directly to the public internet.
  • Obtain consent before monitoring private areas and consider that images are sent to an external cloud service.
  • Use a conventional security system or locally stored recording when evidence retention, tamper resistance, night vision, weatherproofing, or dependable 24/7 operation matters.

Possible upgrades

A microSD card can provide local snapshots, but the baseline GPIO arrangement uses pins associated with the microSD interface and would need redesigned wiring and firmware. MQTT or Home Assistant can provide better automation and history. A local web server avoids Telegram dependence but needs a secure remote-access design. Battery operation requires a measured power budget and a wake-on-PIR strategy; a sleeping device cannot continuously poll Telegram or respond instantly to /photo.

For newer designs, an ESP32-S3 camera board may offer more capable memory and peripheral options, but its pin map and software are not drop-in compatible with the AI-Thinker tutorial. A Raspberry Pi camera or commercial Wi-Fi camera is a better fit when continuous recording, local processing, storage, or managed reliability is the priority.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Site Office

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.