Irfan Mohammed

Projects / Door lock

An offline face-recognition door lock

Firmware for a door lock that recognises faces on the microcontroller itself. The unlock decision never waits on a network call, so a Wi-Fi outage can’t lock you out and a network attacker can’t let anyone in.

Role
Solo: hardware selection, firmware, CI
Hardware
ESP32-S3-EYE, Freenove bring-up board, BME280
Stack
C, ESP-IDF 5.3, FreeRTOS, ESP-WHO / ESP-DL
Code
github.com/irfan416/face-door-lock

Why I built it

Most of my security work happens above the operating system: identities, email, logs. I wanted a project that would force me to deal with the layer underneath, where memory is tight, there’s no OS to lean on, and a design mistake shows up as a door that won’t open.

A door lock is also a good security problem in its own right. It has a physical attacker, a network attacker, and a failure mode where locking people out is almost as bad as letting the wrong person in. That pushed me toward one rule that shapes the whole design.

Design rule: The unlock decision must never depend on a network call. Recognition runs on the device. Wi-Fi, when it’s added, is only for logging and alerts.

Architecture

Everything on the unlock path stays inside the ESP32-S3. Camera frames go into PSRAM, the face model runs locally, and the decision logic drives the lock and status LED. The network sits off to the side and nothing on the critical path waits for it.

Figure 1. Runtime architecture. Highlighted blocks are the unlock path; nothing on it calls the network. Recognition and the actuator are the current milestone.

Choosing the hardware

I wrote this choice up as an architecture decision record before buying anything. The project needed on-device face recognition, a physical actuator, I2C sensors, and Wi-Fi later, while still being a firmware project rather than a Linux one.

OptionForAgainst
ESP32 (original)Already planned for the earlier sensor workNot enough RAM or PSRAM for recognition, and no official AI tooling
STM32Excellent deterministic real-time firmwareNo built-in Wi-Fi, and no first-party face recognition, so I’d be building an ML pipeline from scratch
Raspberry Pi Zero classPlenty of computeFull Linux, slow boot, and it turns the project into embedded Linux work instead of firmware
ESP32-S3 module + separate cameraFlexible camera placementI’d have to wire and validate the camera, pin map and power myself
ESP32-S3-EYEVendor board built for this: S3, OV2640, 8 MB PSRAM, 8 MB flash, all pre-validated, and it runs ESP-WHO with no cloudTies me to Espressif’s model format; fixed camera position constrains the enclosure

The 8 MB of PSRAM was the deciding factor, because camera frame buffers and model weights both need it. The ADR also says when I’d revisit the decision: if recognition latency can’t meet my requirement on this board even after optimisation.

Built to be tested

Firmware is hard to test because most of it only runs on the chip. I split every module into two parts: a thin layer that talks to ESP-IDF, and pure C logic that doesn’t include any ESP-IDF headers. The pure parts compile with plain gcc on a laptop or a CI runner.

My own enums instead of ESP-IDF types

The hardware reset reason is translated into my own door_lock_reset_reason_t at the edge. Logic that decides what a watchdog or brownout reset means can then be tested on a host.

Trade-off: one small mapping function per hardware type, in exchange for logic I can test in milliseconds.

Two board targets behind one Kconfig switch

A TARGET_BOARD choice selects the ESP32-S3-EYE (camera and LED) or a Freenove bring-up board (BME280 and buttons). I can develop sensor and input code before it has to share the EYE’s pins.

Trade-off: #ifdef blocks in app_main, kept small and at the top level.

Status as a state, not as blink code

The LED shows idle, active or error, and the blink period for each state comes from a pure function. When I add new states, the visible behaviour has a unit test.

CI pipeline

Every pull request runs three GitHub Actions jobs. A change that breaks the real ESP-IDF build or a host test can’t be merged without me noticing.

Figure 2. Build and test pipeline. Static analysis is advisory for now (dashed) while I bring older files up to the format.

Photos and demo

What I learned

  • Write the decision down before you buy the board. The ADR made me name what I was giving up, like Espressif lock-in and fixed camera placement, instead of finding out later.
  • Testability is an architecture choice. It has to be designed in at the module boundary. Adding tests afterwards would have meant rewriting the modules.
  • Fail-safe beats feature-rich. Keeping the network off the critical path ruled out some convenient features, like cloud face matching, and made the threat model much simpler.

What’s next

  • Run face detection and enrolment with ESP-WHO and measure latency against my target.
  • Drive a lock actuator through a relay or MOSFET, with a fail-secure default.
  • Add I2C liveness and tailgating sensors so a printed photo isn’t enough.
  • Add Wi-Fi for audit logs and alerts, kept strictly off the unlock path.