Fareed Mohmed← All projects

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

ESP32-CAMcamera + Wi-FiWi-Fi networkMJPEG streamComputerPython + OpenCVAI modelYOLOResultboxes and labels

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.

ConnectionWhere it goes
Adapter TXBoard U0R
Adapter RXBoard U0T
Adapter GNDBoard GND
5 V supplyBoard 5V pin
Board IO0 to GNDOnly while uploading (flash mode). Remove it, then press RESET to run

Steps

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

PartWhat to look for
ESP32-CAM board (AI-Thinker) with OV2640 cameraIncludes the camera on the board
USB-to-serial adapter, 3.3 V logicFTDI or CP2102
5 V power supply, 1 AA weak supply makes the board reset
Jumper wiresIO0 to GND for flashing
Computer with Python 3For the detection program

Do and do not