How to Build a Security Camera with the ESP32-CAM
Share
The ESP32-CAM packs a camera, Wi-Fi, and a microcontroller onto a board smaller than a matchbox, which makes it the cheapest serious way into DIY security cameras. This guide builds a working camera end to end, from flashing to live streaming. Because the ESP32-CAM is famously fussy to program, Compoden's AI build assistant can ship the board with the right USB programmer and sample code so your first upload actually works.
What you'll build
A Wi-Fi camera that streams live video to your browser or phone on the local network. It can detect motion, capture a snapshot to an SD card, and optionally send an alert. With a stable supply and a sensible mounting spot, it works as a doorway watcher, a pet cam, or a parking-spot monitor.
Parts you need (rough BOM)
- ESP32-CAM board with the OV2640 camera
- FTDI USB-to-serial programmer (or an ESP32-CAM-MB adapter)
- 5V supply capable of at least 1A (the camera draws current spikes)
- MicroSD card for snapshot storage
- Jumper wires and a breadboard for flashing
- External antenna version if your Wi-Fi is weak
- A small enclosure for permanent mounting
How it works
The ESP32-CAM captures frames from the OV2640 camera and serves them over Wi-Fi as an MJPEG stream that any browser can open. A built-in web server hosts a page with the live feed and camera settings. For motion detection, the firmware compares successive frames and saves a snapshot to the SD card or fires an alert when enough pixels change.
Wiring overview
To flash, connect the FTDI programmer: TX to U0R, RX to U0T, and shared ground, with the programmer set to 5V. Crucially, jumper GPIO0 to ground to enter flashing mode, then remove that jumper to run. Power the board from a solid 5V supply rather than the FTDI's 3.3V line, because the camera browns out otherwise. The SD card uses the onboard slot, so no extra wiring is needed.
Build steps
- Wire the FTDI programmer and add the GPIO0-to-ground jumper.
- In the Arduino IDE, select the AI Thinker ESP32-CAM board.
- Load the CameraWebServer example and enter your Wi-Fi credentials.
- Press the on-board reset, upload, then remove the GPIO0 jumper and reset again.
- Open the serial monitor to find the camera's IP address.
- Browse to that IP and confirm the live stream loads.
- Add motion detection and snapshot-to-SD if you want recording.
- Move to a stable 5V supply and mount the camera in its enclosure.
Code outline
- Include the camera and web-server libraries and set the AI Thinker pin map.
- In setup(), initialise the camera with your chosen resolution and connect Wi-Fi.
- Start the web server that serves the stream and a control page.
- For motion: grab a frame, compare a downscaled version with the previous one.
- If the difference passes a threshold, save a JPEG to the SD card and timestamp it.
- Keep the loop light so the stream stays smooth.
Troubleshooting
If uploads fail, the most common causes are a missing GPIO0 jumper, swapped TX and RX, or an underpowered programmer; use a 5V supply. If the stream is laggy, lower the resolution and frame size. A brown-out reset loop almost always means the supply cannot handle the camera's current spikes, so move to a 1A or larger adapter. Weak Wi-Fi at range calls for the external-antenna version.
Going further
Push snapshots to Telegram or email on motion, add a PIR sensor so the camera only wakes on movement to save power, or feed the stream into a home-automation dashboard. For on-device recognition such as face or object detection, a more powerful board like the nvidia-jetson-nano-4gb handles real AI workloads the ESP32-CAM cannot.
Build it with Compoden's AI
Describe a Wi-Fi security camera to Compoden's AI build assistant and it matches a kit with the ESP32-CAM, the right programmer, a suitable 5V supply, and an SD card, then ships sample code that streams on first boot. You skip the flashing frustration that stops most beginners. Browse boards and modules at /collections/all.
Want a camera you built yourself watching the door? Tell Compoden's AI and get a kit that streams out of the box.
FAQ
Why does my ESP32-CAM keep resetting? Almost always power. The camera draws current spikes, so use a 5V supply rated for 1A or more rather than powering it from the FTDI's 3.3V line.
Can I view the camera from outside my home network? Locally it works out of the box. For remote viewing, route the stream through a cloud service or use port forwarding carefully, since exposing a camera to the internet has security risks.
Do I need a separate programmer? Yes, unless your board has the ESP32-CAM-MB USB adapter. A standard FTDI programmer with the GPIO0 jumper trick is the usual route.