In this CircuitMagic project you will build an AI door greeter: a tiny ESP32-S3 camera spots a face, then waves a “HI!” flag with a servo, lights an LED and plays a chime. The face detection model comes ready-made from Espressif and runs on the board itself, so there is nothing to train and no internet connection is needed.
Face detection vs face recognition
Face detection answers one question: is there a face in the picture, and where is it? Face recognition goes further and tries to work out who the person is. This greeter only uses detection. It does not identify anyone, and it does not store or send any images.
Required components
- Seeed Studio XIAO ESP32S3 Sense (ESP32-S3 with 8 MB PSRAM and OV2640 camera)
- SG90 micro servo
- LED and a 220 ohm resistor
- Active buzzer (5 V or 3.3 V type)
- Jumper wires and a breadboard
- 5 V USB power supply and a USB-C data cable
The face detection library only runs on the ESP32-S3 (and newer chips). A classic ESP32-CAM board is not supported for this project.
How it works
- Camera: the OV2640 captures a small 240×240 frame in RGB565 format.
- Stage 1 (MSR): a fast model scans the frame and suggests possible face areas.
- Stage 2 (MNP): a second model checks each candidate and keeps the real faces.
- Greet: when a face is confirmed, the servo waves the flag, the LED lights and the buzzer chimes.
- Cooldown: the greeter waits 5 seconds so it doesn’t greet the same person over and over.
Pin connections
Unplug USB power before wiring. The camera plugs into the XIAO’s expansion board, so it needs no wires.
| XIAO ESP32S3 pin | Connection |
|---|---|
| D3 (GPIO4) | Servo signal (orange wire) |
| 5V | Servo red wire |
| GND | Servo brown wire |
| D0 (GPIO1) | 220 ohm resistor, then LED long leg (+) |
| GND | LED short leg (−) |
| D1 (GPIO2) | Buzzer + |
| GND | Buzzer − |
Connect all grounds together. If the board resets when the servo moves, power the servo from a separate 5 V supply and connect that supply’s GND to the XIAO’s GND.
Arduino IDE setup
- In Tools › Board › Boards Manager, install esp32 by Espressif Systems version 3.0.7. Releases from 3.1 onward removed the face detection library this sketch uses.
- In Library Manager, install ESP32Servo by Kevin Harrington.
- Select Board: XIAO_ESP32S3 and set PSRAM: OPI PSRAM.
- Select the port, then upload the sketch below.
Complete Arduino code
Note: this sketch is new for this project and has not yet been tested on hardware by CircuitMagic. If you build it, let us know how it works in the comments.
// CircuitMagic - AI Door Greeter (face detection on ESP32-S3)
// Board: XIAO ESP32S3 Sense | Core: esp32 3.0.7 | PSRAM: OPI PSRAM
// Library: ESP32Servo
#include <list>
#include "esp_camera.h"
#include "human_face_detect_msr01.hpp"
#include "human_face_detect_mnp01.hpp"
#include <ESP32Servo.h>
// XIAO ESP32S3 Sense camera pins
#define PWDN_GPIO_NUM -1
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 10
#define SIOD_GPIO_NUM 40
#define SIOC_GPIO_NUM 39
#define Y9_GPIO_NUM 48
#define Y8_GPIO_NUM 11
#define Y7_GPIO_NUM 12
#define Y6_GPIO_NUM 14
#define Y5_GPIO_NUM 16
#define Y4_GPIO_NUM 18
#define Y3_GPIO_NUM 17
#define Y2_GPIO_NUM 15
#define VSYNC_GPIO_NUM 38
#define HREF_GPIO_NUM 47
#define PCLK_GPIO_NUM 13
// Greeter outputs
#define SERVO_PIN D3
#define LED_PIN D0
#define BUZZER_PIN D1
const uint32_t COOLDOWN_MS = 5000;
// Two-stage detector from Espressif ESP-DL
HumanFaceDetectMSR01 s1(0.1F, 0.5F, 10, 0.2F);
HumanFaceDetectMNP01 s2(0.5F, 0.3F, 5);
Servo flagServo;
uint32_t lastGreet = 0;
bool initCamera() {
camera_config_t config = {};
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sccb_sda = SIOD_GPIO_NUM;
config.pin_sccb_scl = SIOC_GPIO_NUM;
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_RGB565; // the face detector needs RGB565
config.frame_size = FRAMESIZE_240X240;
config.jpeg_quality = 12;
config.fb_count = 2;
config.fb_location = CAMERA_FB_IN_PSRAM;
config.grab_mode = CAMERA_GRAB_LATEST;
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
Serial.printf("Camera init failed with error 0x%x\n", err);
return false;
}
return true;
}
// Wave the flag, light the LED and play a two-beep chime
void greet() {
digitalWrite(LED_PIN, HIGH);
digitalWrite(BUZZER_PIN, HIGH); delay(150);
digitalWrite(BUZZER_PIN, LOW); delay(100);
digitalWrite(BUZZER_PIN, HIGH); delay(150);
digitalWrite(BUZZER_PIN, LOW);
for (int i = 0; i < 3; i++) {
flagServo.write(45); delay(300);
flagServo.write(135); delay(300);
}
flagServo.write(90);
digitalWrite(LED_PIN, LOW);
}
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
if (!psramFound()) {
Serial.println("PSRAM not found. Set Tools > PSRAM to OPI PSRAM.");
while (true) delay(1000);
}
if (!initCamera()) {
while (true) delay(1000);
}
// The camera uses LEDC timer 0, so give the servo another timer
ESP32PWM::allocateTimer(1);
flagServo.setPeriodHertz(50);
flagServo.attach(SERVO_PIN, 500, 2400);
flagServo.write(90);
Serial.println("Ready - waiting for a visitor...");
}
void loop() {
camera_fb_t *fb = esp_camera_fb_get();
if (!fb) { delay(100); return; }
std::list<dl::detect::result_t> &candidates =
s1.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3});
std::list<dl::detect::result_t> &faces =
s2.infer((uint16_t *)fb->buf, {(int)fb->height, (int)fb->width, 3}, candidates);
size_t count = faces.size();
if (count > 0) {
Serial.printf("Faces: %u score %.2f\n", (unsigned)count, faces.front().score);
}
esp_camera_fb_return(fb);
if (count > 0 && millis() - lastGreet > COOLDOWN_MS) {
greet();
lastGreet = millis();
}
delay(50);
}
Expected output
Open Serial Monitor at 115200 baud. When you face the camera, the sketch prints the number of faces and a detection score, then the servo waves, the LED lights and the buzzer beeps twice. It then waits 5 seconds before it can greet again.
Troubleshooting
- “human_face_detect_msr01.hpp: No such file”: you are on core 3.1 or later. Install esp32 core 3.0.7.
- Camera init failed: check that the camera ribbon is seated and PSRAM is set to OPI PSRAM.
- Board resets when the servo moves: power the servo from a separate 5 V supply with a shared GND.
- Faces are missed: use good light, keep the face fairly close and near the centre of the frame, and look toward the camera.
- Picture upside down: after the camera starts, add
esp_camera_sensor_get()->set_vflip(esp_camera_sensor_get(), 1);
Try next
Show a “Welcome!” message on a small OLED screen, send a notification to your phone when someone arrives, or add a pan servo so the camera follows faces around the room. See more CircuitMagic electronics projects for related tutorials.










