Weâve all been there: you walk up to your front door carrying three bags of groceries, a lukewarm coffee you swore youâd finish, and a piece of mail that is definitely a bill. You donât have a free hand to dig for keys. You try to awkwardly balance the coffee on your knee while rummaging through your pockets, and⌠disaster strikes. The coffee spills, the groceries tumble, and youâre left standing on your porch re-evaluating your life choices.
Keys are a primitive technology for primitive times. Itâs 2026. Your phone unlocks by looking at you; your door should do the same.
Today, we are going to build a smart, biometric door lock using the ESP32-CAM. Weâll program it to scan a video feed, recognize your specific face (and ignore your shady roommate), and fire a heavy-duty 12V solenoid to pop the door open automatically. No magic blue smoke, no dropped groceriesâjust pure, futuristic convenience.
(Note: We built an RFID Door Lock back in Project 16, but this takes security up a notch by relying on biometrics instead of a plastic tag that can be stolen!)
The ESP32-CAM is a tiny, $10 microcontroller that features built-in Wi-Fi and a camera interface (usually paired with an OV2640 sensor). Espressif (the company that makes the ESP32) provides an incredible camera web server example out of the box that includes facial detection and recognition algorithms built right in.
Hereâs the flow:
HIGH.To build this facial recognition lock, youâll need the following gear. (Note: The ESP32-CAM doesnât have a built-in USB port, so you must use an FTDI programmer to upload the code!)

This circuit is a tale of two voltages. We have the sensitive 5V logic of the ESP32-CAM and the brute-force 12V power required to move the heavy metal solenoid. We use a Relay to keep them safely separated.
Because the ESP32-CAM is doing some heavy lifting with AI, we need to ensure the Arduino IDE is set up correctly.
esp32, and install it.We are going to use the official Espressif Camera Web Server example, but we need to inject a few lines of code to trigger our relay when a face is recognized.
#define CAMERA_MODEL_AI_THINKER and comment out the other models.const char* ssid = "YOUR_WIFI_NETWORK";
const char* password = "YOUR_WIFI_PASSWORD";
int lockPin = 4; // Using GPIO 4 (Flash LED) to trigger the relay
setup() function, configure the pin:pinMode(lockPin, OUTPUT);
digitalWrite(lockPin, LOW); // Ensure the lock is engaged on startup
The actual facial recognition logic happens in a secondary file called app_httpd.cpp. Look at the tabs at the top of your Arduino IDE and click on app_httpd.cpp.
Scroll down (or use Ctrl+F) to find the face_recognize function block. You are looking for a line that looks like this:
if (matched_id > 0) {
This is the exact moment the AI realizes it knows who you are. We need to inject our relay trigger right here. Modify the code block to look like this:
if (matched_id > 0) {
Serial.printf("Match Face ID: %u\n", matched_id);
// --- OUR CUSTOM LOCK LOGIC ---
Serial.println("Face Recognized! Opening Door...");
digitalWrite(4, HIGH); // Trigger Relay
delay(3000); // Keep door unlocked for 3 seconds
digitalWrite(4, LOW); // Lock door again
// -----------------------------
} else {
Serial.println("Match Face: Not Found");
}
The ESP32-CAM doesnât have a USB port. You must use the FTDI adapter.
http://192.168.1.100).Once enrolled, the next time you step into the frame, the web interface will draw a green box around your face, print Hello Subject 0, and youâll hear the satisfying THUNK of your 12V solenoid pulling back.
Welcome to the future. Now go pick up your spilled coffee.