An ESP32-CAM can find faces in its own video stream, with no cloud service and no PC: the detection runs on the chip itself, which is what people mean by edge AI. It's also one of the most confusing ESP32 tutorials to follow today, because the feature has moved between versions of the Arduino-ESP32 core and older guides describe code that no longer exists.
Quick answer: the Face Detection and Face Recognition toggles live in Espressif's CameraWebServer example, but only on Arduino-ESP32 core 2.0.x. They were removed from the example in core 3.x. So in Boards Manager install esp32 version 2.0.17, open File → Examples → ESP32 → Camera → CameraWebServer, select CAMERA_MODEL_AI_THINKER, set Partition Scheme: Huge APP and PSRAM: Enabled, upload, open the board's IP address, set the resolution to CIF or lower, and switch Face Detection on.
Detection finds faces and draws a box around them; recognition says whose face it is. The 2.0.x example does both, for a handful of enrolled faces.
What You Need
- An AI-Thinker ESP32-CAM with its OV2640 camera. The example's pin map assumes this board.
- A way to program it: an ESP32-CAM-MB base (easiest) or a 3.3 V/5 V USB-serial adapter. The board itself has no USB port.
- A solid 5 V supply. Camera start-up plus Wi-Fi draws current spikes; a weak USB port or thin cable causes brownouts and camera init failed errors that look like software bugs.
- PSRAM. Detection needs the board's external PSRAM for frame buffers. The AI-Thinker board has it; some clones don't, and those compile fine but fail when detection starts.
Wiring, upload steps and the boot-button routine are covered in the ESP32-CAM web server guide; this page assumes you can upload a sketch to the board.
Which Arduino-ESP32 Core Has Face Detection?
| Core version | Face detection in CameraWebServer | Library underneath |
|---|---|---|
| 1.0.6 (2021) | Yes, plus recognition | esp-face (fd_forward, MTMN) |
| 2.0.x (2.0.17 is the last) | Yes, plus recognition | ESP-DL (HumanFaceDetectMSR01 / MNP01) |
| 3.x (current) | No: removed from the example | — |
Check yours in Tools → Board → Boards Manager → esp32. If it's 3.x and you want the toggle, choose 2.0.17 from the version list and install it. You can switch back later; your other sketches aren't affected, though code written for 3.x-only APIs (such as ledcAttach()) won't compile on 2.0.17.
Step by Step on Core 2.0.17
- Open File → Examples → ESP32 → Camera → CameraWebServer.
- In the main tab, comment out the default model and uncomment
#define CAMERA_MODEL_AI_THINKER. - Enter your 2.4 GHz Wi-Fi
ssidandpassword. - Tools → Board: AI Thinker ESP32-CAM (or ESP32 Wrover Module), Partition Scheme: Huge APP (3MB No OTA/1MB SPIFFS), PSRAM: Enabled.
- Upload, then open the Serial Monitor at 115200 baud and press reset. It prints
Camera Ready! Use 'http://192.168.x.x' to connect. - Open that address, click Start Stream, set Resolution to CIF (400x296) or smaller, and switch on Face Detection.
The face-detection switches are greyed out above CIF: the detector needs a small frame to keep up. QVGA (320x240) is the usual sweet spot between speed and how far away a face can be.
Recognition: switch on Face Recognition, face the camera, and click Enroll Face. The board stores a few faces (up to 7 in the stock example) and labels each one by ID when it sees it again. Enrolled faces live in RAM in the stock example, so they're lost when the board restarts.
Steps
- 1On Arduino-ESP32 core 2.0.17, flash CameraWebServer with PSRAM enabled, Huge APP partitioning and CAMERA_MODEL_AI_THINKER
- 2Open the board's IP address and confirm the live stream loads before touching detection
- 3Set the resolution to QVGA or CIF, switch on Face Detection, and confirm a box appears on your own face
- 4Test at the edges of the frame and at an angle; detection should hold up to roughly 30 degrees off-centre
- 5Dim the room and retest: a drop in detection rate confirms lighting sensitivity, not a wiring fault
- 6Add a second person and confirm both get their own box before building anything on top
How the Detection Works
The core 2.0.x example uses Espressif's ESP-DL library with two small neural networks in sequence. The first (HumanFaceDetectMSR01) quickly proposes candidate face regions; the second (HumanFaceDetectMNP01) checks each candidate and refines the box. They run on the camera frame converted to RGB, separately from the JPEG stream your browser receives, and the boxes are drawn onto the streamed image.
Because the networks run on the ESP32's own two cores, everything about the frame matters:
- Smaller frames run faster. Expect a few frames per second with detection on at QVGA, fewer at CIF, and noticeably more without it.
- Faces must be big enough in the frame. A face that covers only a few dozen pixels gets missed, so range drops quickly at small resolutions; a face at arm's length to a couple of metres in good light is typical.
- Lighting dominates. Even, front-facing light works best; a bright window behind the person is the most common cause of missed faces.
Multiple Faces
The detector isn't limited to one face: each face it finds gets its own box. Reliability drops as faces get smaller, overlap or turn sideways, so a group a few metres away usually shows only the nearest faces. That's the expected behaviour of a model small enough to run on this chip, not a setting to fix. If reliable counting of a crowd is the goal, run a larger model on a Raspberry Pi or PC and use the ESP32-CAM only as the camera.
Doing Something When a Face Appears
The example only draws boxes. To react, edit app_httpd.cpp. In stream_handler(), the detector's output is a list called results; its size is the number of faces in the current frame. Add a few lines right after the detection call:
// app_httpd.cpp, inside stream_handler(), after the face detection inference
#define ALERT_PIN 13 // a free pin on the AI-Thinker board
static bool alertReady = false;
if (!alertReady) { pinMode(ALERT_PIN, OUTPUT); alertReady = true; }
digitalWrite(ALERT_PIN, results.size() > 0 ? HIGH : LOW);The exact surrounding code differs between example versions, so search the file for infer( and add the lines after the second (MNP01) call.
Which pin? GPIO 13 is the cleanest free pin on the AI-Thinker board. GPIO 4 is the bright flash LED (it will light it), and GPIO 33 is the small red LED on the back (active LOW), handy as an indicator. Drive a buzzer or relay through a transistor or a relay module, not straight from the pin. The full pin situation is in the ESP32-CAM pinout guide.
Limits to Expect
- Small recognition set. Recognition works for a handful of enrolled faces under similar lighting. It isn't a security system and is easily fooled by a photo.
- No memory across restarts in the stock example, unless you add code to save enrolled faces to flash.
- Low frame rate with detection on, especially with recognition as well.
- Lighting and angle sensitivity: strong backlight, dim rooms, and faces turned more than about 30–40° away all cut the detection rate.
On-Device Detection vs. Cloud-Based Recognition
Once a project needs more than "a face is present," the choice is between pushing more model onto the ESP32 itself or offloading the harder work to something with real compute behind it. Both are legitimate paths, and the right one depends mostly on how much latency and internet dependency the project can tolerate.
| On-device detection (this guide) | Cloud-based recognition | |
|---|---|---|
| Identifies whose face | A few enrolled faces | Yes, at scale |
| Works with no internet connection | Yes | No |
| Typical response latency | Under 100ms | 300ms-2s depending on connection |
| Ongoing cost | None | Usually per-request API pricing |
| Setup complexity | Low -- built into the stock example | Higher -- requires an account, API integration, and image upload code |
A common middle ground: use the ESP32-CAM's on-device detection purely as a trigger -- only bother capturing and uploading a frame to a cloud recognition service when a face is actually present, instead of streaming continuously. That keeps bandwidth and API costs down while still getting recognition when it's genuinely needed.
Real Project Ideas Built on Basic Detection
Detection alone, without recognition, is still the core of several genuinely useful builds:
- Presence-triggered recording -- only save video or photos to microSD when a face enters frame, instead of continuously, which saves card space and makes later review far faster
- Doorbell wake-up -- pair with a PIR sensor as a coarse first-stage trigger, then confirm with face detection before sending a phone notification, cutting down false alerts from passing cars or blowing leaves
- Occupancy-aware lighting or displays -- turn on a screen, light, or fan only when someone is actually looking at the device, rather than on a fixed timer
- Simple attendance or headcount logging -- log a timestamp each time a new face appears in frame at a fixed station, useful for rough foot-traffic counting where exact identity doesn't matter
- Photobooth-style triggers -- fire a countdown and capture the instant a face is detected and centered, without a physical button
None of these need recognition -- they need to know a person is there, and that's exactly what this setup already provides out of the box.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| No Face Detection switch in the web page | Core 3.x | Install esp32 core 2.0.17 in Boards Manager |
| Switches greyed out | Resolution above CIF | Set CIF, QVGA or smaller |
| Camera init failed with error 0x105 | Wrong CAMERA_MODEL_, loose ribbon cable | Select AI_THINKER; reseat the camera ribbon |
| Camera init failed 0x101 / crashes when detection starts | PSRAM disabled, or a board without PSRAM | Tools → PSRAM: Enabled; use a genuine AI-Thinker board |
| Sketch too big | Default partition scheme | Huge APP (3MB No OTA) |
| Brownout detector was triggered | Weak 5 V supply | Short thick cable, 5 V 2 A supply, 470 µF capacitor on 5V/GND |
| Faces rarely detected | Backlight, small face, high mount | Light the face from the front, move closer, mount at eye level |
| Recognized faces forgotten after reset | Enrolment is kept in RAM | Re-enroll, or add code to store them in flash |
Power and Heat
With Wi-Fi streaming and detection running, the ESP32-CAM works hard and gets warm. Budget for a 5 V supply that can deliver well over 500 mA in bursts, not a laptop port through a long cable, and give the board some airflow if it runs continuously in an enclosure. A board that resets every few minutes under load is almost always short of power, not faulty.
Improving Detection Accuracy Without Changing Hardware
Before reaching for a bigger model or a second board, a handful of software-only adjustments usually close most of the gap between "works in good conditions" and "works reliably":
Fix the exposure, don't let it hunt. The camera's auto-exposure routine actively fights detection in mixed lighting -- it keeps adjusting brightness as faces enter and leave frame, and each adjustment briefly degrades the grayscale image the detector scans. Setting a fixed exposure value (turn off AEC SENSOR in the web page's advanced settings, or call s->set_exposure_ctrl(s, 0) and then s->set_aec_value(s, ...) in code) for a fixed-lighting installation, like a hallway or desk, removes that source of jitter entirely.
Mount at face height, not above it. A camera angled downward from a high mount -- common in doorbell and security placements -- captures faces at an angle the detector wasn't tuned for. Straight-on, roughly eye-level placement measurably outperforms a steep downward angle, even at identical distance and lighting.
Give the detector a consistent background. A cluttered or high-contrast background behind the subject increases false triggers, since the sliding-window scan is scoring edge patterns, not understanding scene content. A plain wall behind the expected face position, where that's controllable, noticeably reduces false positives.
Don't skip the warm-up frame. The very first frame or two after the camera initializes is sometimes underexposed while auto-exposure settles -- discarding the first 2-3 frames before starting to log or act on detections avoids a false "no face" reading on startup.
Beyond the Stock Example
| Approach | What you get | Effort |
|---|---|---|
| CameraWebServer on core 2.0.17 (this guide) | Detection plus basic recognition, in a browser | Lowest: a few settings |
| ESP-WHO (Espressif, ESP-IDF) | Maintained detection and recognition examples, best on the ESP32-S3 | ESP-IDF instead of the Arduino IDE |
| TensorFlow Lite Micro or Edge Impulse | Your own trained model (people, objects, gestures) | Training a model and integrating it |
| ESP32-CAM as a camera, Pi or PC runs the AI | Large models, many faces, real recognition | A second device; see ESP32-CAM YOLO object detection |
For new face projects, an ESP32-S3 camera board is worth considering: it has vector instructions that ESP-DL uses for much faster inference, and native USB. Espressif's current face examples target it first.
FAQ
Why is there no face detection option in my CameraWebServer? You're on Arduino-ESP32 core 3.x, which removed it from the example. Install core 2.0.17.
Can the ESP32-CAM recognize faces? Yes, a few enrolled faces, using the Face Recognition and Enroll Face buttons on core 2.0.x. It's not reliable enough for security.
Which resolution should I use? QVGA (320x240) for the best balance; detection only works at CIF (400x296) or lower.
Does it need the internet? No. Detection and recognition run on the board; Wi-Fi is only used to show the stream in your browser.
Does it work in the dark? Poorly. The flash LED helps at close range; for night use you need IR lighting and an IR-sensitive camera, as in the ESP32-CAM night light project.
Will other ESP32 camera boards work? Yes, if they have PSRAM and you select the matching CAMERA_MODEL_ line.
Where to Go Next
- ESP32-CAM web server setup: uploading, streaming and power in depth
- ESP32-CAM pinout: which pins are free for alerts and sensors
- ESP32-CAM PIR motion camera: a PIR as a low-power first trigger before detection
- ESP32-CAM photo capture to microSD: save a picture when a face appears




