ESP32 S3 Camera - Send Photo to Telegram When Motion Detected
This tutorial instructs you how to build a security camera that sends a photo to your phone. A PIR motion sensor watches the room. When somebody walks in front of it, the ESP32 S3 takes a photo and sends it to you with Telegram. You get the photo in a few seconds, anywhere in the world.

What you'll build:
- Your own Telegram bot that sends you messages
- An ESP32 S3 camera with a PIR motion sensor
- A photo on your phone every time the sensor sees a movement
- A quiet time, so you do not get 50 photos of the same person
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
※ NOTE THAT:
The ESP32 S3 camera board has 40 pins, but the screw terminal block and the breakout board have 44 pins. They still work together. Put the camera board in the center of the 44-pin board, so 2 pins stay free on the left side and 2 pins stay free on the right side.
The screw terminal block lets you connect wires with a screwdriver, with no soldering. The breakout board gives you easy pin headers for a breadboard.
Overview of Telegram
Telegram is a free chat application for your phone and your computer. Telegram lets you make a bot. A bot is a robot friend in your chat list. Your ESP32 S3 sends the photo to the bot, and the bot shows it to you.
You need two secret texts:
| Name | What it is | Looks like | |
|---|---|---|---|
| Bot token | The password of your bot | 8012345678 | AAHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| Chat ID | The number of your chat | 123456789 |
※ NOTE THAT:
Never show your bot token to anybody, and never put it on a website or on GitHub. Somebody with your token can control your bot.
Step 1: Make Your Bot
- Install Telegram on your phone, and make an account.
- In Telegram, search for @BotFather. It has a blue tick.
- Open the chat with BotFather and talk to it like this:
BotFather
- Copy the bot token from the last message and keep it safe.
Step 2: Find Your Chat ID
- In Telegram, search for the name of your new bot and open the chat.
- Send any message to your bot, for example hello. This step is necessary. Telegram does not let a bot write to you before you have written to it.
ArduinoBot
- Open this address in your web browser. Put your own bot token in the place of <YOUR_BOT_TOKEN>:
- The browser shows a long text. Look for "chat":{"id":. The number after it is your chat ID:
※ NOTE THAT:
Does the browser show {"ok":true,"result":[]} with nothing inside? Then you did not send a message to your bot yet. Go back to step 2, send hello to your bot, then load the address again.
※ NOTE THAT:
Many other tutorials tell you to ask the bot @myidbot with the message /getid. That bot belongs to somebody else, and very often it does not answer at all. The web address above always works, because it asks Telegram directly.
※ NOTE THAT:
Forgot step 2? Then the ESP32 S3 shows the answer Forbidden: bot can't initiate conversation with a user in the Serial Monitor. Open the chat with your bot and send it any message, then try again.
Step 3: Put Them in the Code
Open the code and change these four lines:
Overview of PIR Motion Sensor
A PIR motion sensor sees the heat of a human body. PIR means "Passive InfraRed". When a warm body moves in front of it, the OUT pin goes HIGH.

Key Specifications
| Item | Value |
|---|---|
| Power | 5V |
| Output | 3.3V HIGH when it sees a movement, LOW when it sees nothing |
| Distance | 3 to 7 meters (you can change it) |
| Angle | about 110° |
| Warm-up time | 30 to 60 seconds after power on |
The sensor has two small orange screws. Turn the time delay screw all the way to the left, so the output stays HIGH for only about 3 seconds.
For more detail about the motion sensor, see the ESP32 S3 - Motion Sensor tutorial. To save the photos on a microSD card instead of sending them to Telegram, see the ESP32 S3 Camera - Save Photo to SD Card When Motion Detected tutorial.
Wiring Diagram between PIR Motion Sensor and ESP32 S3
Connect the PIR motion sensor to your ESP32 S3 with three jumper wires.

This image is created using Fritzing. Click to enlarge image
| PIR Sensor Pin | ESP32 S3 Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| OUT | GPIO21 |
Safety Notes
The PIR sensor needs 5V on its VCC pin, not 3.3V. With 3.3V it looks like it works, but it gives wrong signals. Its OUT pin gives 3.3V, which is correct for the ESP32 S3.
The camera uses GPIO4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17 and 18. Do not use these pins for the sensor. GPIO21 is free, so we use it.
Arduino IDE Settings for ESP32 S3 Camera
The camera does not work with the default settings of the Arduino IDE. You must change some items in the Tools menu before you upload the code.
| Tools Menu Item | Select This |
|---|---|
| Board | ESP32S3 Dev Module |
| Flash Size | 16MB (128Mb) |
| PSRAM | OPI PSRAM |
| Partition Scheme | Huge APP (3MB No OTA/1MB SPIFFS) |
| CPU Frequency | 240MHz (WiFi) |
| USB Mode | Hardware CDC and JTAG |
| Upload Mode | UART0 / Hardware CDC |
| Upload Speed | 921600 |
| USB CDC On Boot | Enabled |
※ NOTE THAT:
PSRAM must be OPI PSRAM, and Partition Scheme must be Huge APP. Change Flash Size first, because the list of Partition Scheme options changes after that.
How To Send a Photo to Telegram
You do not need to install any library. The code talks to Telegram directly.
- Telegram uses https, so we need a secure client.
※ NOTE THAT:
setInsecure() means the ESP32 S3 does not check who the server really is. For a small home project this is fine, and it saves a lot of memory. The photo is still sent through an encrypted connection.
- To send a photo, we use the Telegram address /bot<TOKEN>/sendPhoto. The photo travels inside a multipart message. A multipart message has parts, and a line of text called a boundary separates the parts. This project uses three parts: the chat ID, the text, and the photo.
※ NOTE THAT:
The caption part is the text under the photo in Telegram. Change Motion detected! to any message you like.
- The Content-Length must be the size of everything: the first part, the photo, and the last part.
※ NOTE THAT:
A wrong Content-Length is the most common mistake. Telegram then waits for more data and never answers.
- Send the photo in small pieces. A big write() often fails on a secure connection.
- Read the answer. When everything is fine, the answer of Telegram contains "ok":true.
※ NOTE THAT:
This project uses a small image size (FRAMESIZE_SVGA, 800×600), because a small photo is sent much faster. A photo of 50 KB takes about 3 seconds. A photo of 200 KB takes about 10 seconds.
ESP32 S3 Code
The following code sends a photo to your Telegram chat every time the sensor sees a movement. The quiet time is 30 seconds. To change it, change the line #define QUIET_TIME 30000.
Detailed Instructions
- New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
- Make your Telegram bot and find your chat ID. See the steps above.
- Unplug the USB cable, then wire the PIR sensor as in the table above.
- Turn the time delay screw of the sensor all the way to the left.
- Copy the above code and paste it into the Arduino IDE.
- Change YOUR_WIFI_SSID, YOUR_WIFI_PASSWORD, YOUR_TELEGRAM_BOT_TOKEN and YOUR_TELEGRAM_CHAT_ID.
- Change the settings in the Tools menu. See the table above.
- Compile and upload the code to the ESP32 S3 board by clicking the Upload button in Arduino IDE.

- Open the Serial Monitor in Arduino IDE.

- Press the RESET button one time, then leave the room for 30 seconds. The sensor is warming up.
- Come back and walk in front of the camera.
- Look at your phone. The photo arrives in your Telegram chat, with the text under it:
ArduinoBot

Serial Monitor
The following readings were captured in 2026:
Troubleshooting
The Serial Monitor shows Forbidden: bot can't initiate conversation with a user.
You never wrote to your bot. Open Telegram, find your bot, and send it any message. Then press RESET on the board.
The Serial Monitor shows Unauthorized.
Your bot token is wrong. Copy it again from BotFather. The token has two parts joined by : and you need all of it.
The Serial Monitor shows chat not found.
Your chat ID is wrong. Ask @myidbot again with /getid. Do not put spaces around the number.
The Serial Monitor shows Cannot connect to Telegram.
- Check that your WiFi works. The IP address must appear in the Serial Monitor.
- Some school and company networks block Telegram. Try your phone hotspot.
Telegram never answers, and the board waits.
The Content-Length does not match the real size. Do not change the head and tail texts unless you also change the size.
The photo takes a long time.
Use a smaller image size. FRAMESIZE_VGA (640×480) is about half of SVGA.
The sensor sees a movement all the time.
Wait one full minute after start, turn the sensitivity screw a little to the left, and check that VCC is on 5V.
I get too many photos.
Increase QUIET_TIME from 30000 to 60000 (one minute).
Applications
An ESP32 S3 camera with a motion sensor and Telegram is a complete security camera that costs very little and needs no monthly payment. Here are practical projects you can build with this code:
- WiFi home security camera: Get a photo on your phone the moment somebody enters your house, your hall, or your stairs.
- Package delivery alert: Know at once when the delivery person comes to your door, and see the parcel that was left.
- Baby room monitor: Get a photo when your child gets out of bed at night.
- Pet camera for dogs and cats: See what your pet does while you are at work, without paying for a cloud camera.
- Holiday house watcher: Watch an empty house or a second home from another country.
- Garage and driveway alarm: Get a photo when somebody walks near your car, your bicycle, or your motorbike.
- Office and shop after hours: Keep a photo of every person who moves inside after closing time.
- Garden and wildlife camera: Photograph birds, cats, foxes, or the animals that eat your vegetables at night.
- Elderly care helper: Know that a family member is moving around the house as usual, without a camera running all day.
- Warehouse and farm gate: Watch a place far from your house, where a wired alarm system would be too expensive.
Video Tutorial
Watch the step-by-step video walkthrough for this ESP32 S3 project below.
Challenges
- Beginner: Send a text message with the photo, for example the time since the board started.
- Intermediate: Add a switch that turns the alarm on and off, so you do not get photos when you are at home.
- Advanced: Also save every photo to the microSD card, so you keep a copy even when the internet is down.