Info page · no simulation · Arduino and electronics
ESP32-CAM Object Detection (Learning Page)
How to stream video from an ESP32-CAM board over Wi-Fi and detect objects with a small AI model running on a computer.
This topic cannot be run safely or meaningfully in the simulator, so this page explains it with diagrams, calculations and sample code instead. Everything here is original.
What you will learn
- How the ESP32-CAM board is wired and programmed
- How a video stream is sent over Wi-Fi
- How a computer runs an object-detection model on the frames
In short
The ESP32-CAM is a tiny board with a Wi-Fi chip and a small camera. It is too small to run a large object detector, so the usual way is: the board streams video over Wi-Fi, and a computer reads the stream, runs a ready-made AI model (for example YOLO) and draws boxes and names on the frames.
Try this next
- Count the people in the room and show the number.
- Switch a relay when a certain object is seen.
- Use Edge Impulse to train a small model that runs on the board itself.
Privacy: a camera can record people. Use it only in places where everyone knows about it, do not point it at neighbours, and protect the video stream with a password.
System diagram
The standard Arduino example CameraWebServer (File, Examples, ESP32, Camera) starts a web server on the board. The video stream is at http://BOARD-IP:81/stream.
Wiring for programming
The AI-Thinker ESP32-CAM has no USB connector. You need a USB-to-serial adapter (FTDI, 3.3 V logic) and a 5 V supply that can give at least 500 mA.
| Connection | Where it goes |
|---|---|
| Adapter TX | Board U0R |
| Adapter RX | Board U0T |
| Adapter GND | Board GND |
| 5 V supply | Board 5V pin |
| Board IO0 to GND | Only while uploading (flash mode). Remove it, then press RESET to run |
Steps
- In the Arduino IDE install the ESP32 board package and choose the board "AI Thinker ESP32-CAM".
- Open the CameraWebServer example, set the camera model line to CAMERA_MODEL_AI_THINKER and enter your Wi-Fi name and password.
- Join IO0 to GND, press RESET, and upload. Remove the IO0 wire and press RESET again.
- Open the Serial Monitor at 115200 baud to read the board IP address.
- Open the address in a browser to test the picture.
Then run this Python program on your computer (install with pip install ultralytics opencv-python):
import cv2
from ultralytics import YOLO
model = YOLO("yolov8n.pt") # small model, downloads the first time
cap = cv2.VideoCapture("http://192.168.1.50:81/stream") # use your board IP
while True:
ok, frame = cap.read()
if not ok:
break
result = model(frame, verbose=False)[0] # run the detector
cv2.imshow("ESP32-CAM detection", result.plot()) # draw boxes and names
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cap.release()
cv2.destroyAllWindows()Parts list
| Part | What to look for |
|---|---|
| ESP32-CAM board (AI-Thinker) with OV2640 camera | Includes the camera on the board |
| USB-to-serial adapter, 3.3 V logic | FTDI or CP2102 |
| 5 V power supply, 1 A | A weak supply makes the board reset |
| Jumper wires | IO0 to GND for flashing |
| Computer with Python 3 | For the detection program |
Do and do not
- Do use a good 5 V supply. Most problems come from low power.
- Do remove IO0 from GND before running.
- Do keep the stream on your home network and add a password.
- Do not expect the board alone to run a full YOLO model. It has too little memory.
- Do not connect the adapter TX and RX the wrong way round.