Projects

Embedded

NFC access control

Access control for a sports club’s clubhouse: NFC readers, a controller on an ESP32 running FreeRTOS and a backend that sends permissions to the device without any personal data. In service for years.

UART · ProtobufWi-Fi · HTTPentries →← new indexReaderESP8266 · NFC · LED ringDoor openeropen ControllerESP32 · FreeRTOSCard index · sortedBinary searchRTC · entriesRelayWeb UI · OTAManagementSvelteKit · PostgreSQLMembersCards · Web NFCDevicesAccess logThe device holds card numbers only — names stay on the server.
Status
In production
Area
Embedded
Role
Hardware, firmware, backend
µs
to check a card via binary search
0
personal data stored on the device
LTE
sync over mobile data where there is no Wi-Fi
ESP32ESP8266FreeRTOSProtobuf (nanopb)Node.jsSvelte

Features

The images show the management app and the controller's web UI with made-up demo data; click to enlarge.

Overview

The management app shows members, devices and cards at a glance, plus the entries of the last 30 days and what happened most recently — entries as well as device syncs.

Management overview with entries of the last 30 days and recent events (demo data)

Cards and members

Every card has its number, a status (new, labelled, lost) and the member it currently belongs to. Assigning works from a phone too: the UI reads the card via Web NFC where the browser supports it. Lost or returned cards are missing from the door's next card index.

Card management with card number, status and assigned member (demo data)

Access log

The controller records every entry with time and card number and hands the list over during sync; only the server maps it to a member. Each device authenticates with its own API key.

Access log with member, device and time (demo data)

The controller in the browser

The controller ships its own web UI, served by the ESP32 itself: Wi-Fi status, recent events, device data and a button to sync right away. Firmware updates arrive over Wi-Fi, for the controller and the reader.

Controller web UI with status, sync and recent events (demo data)

Card index on the device

The device holds only the sorted list of valid card numbers, four bytes per card. Over a direct connection it can also be maintained by hand — the fallback in case the server is ever unreachable.

Card index on the controller: card numbers, editable by hand (demo data)

Relay, reader and LED ring

How long the relay keeps the door open, which pins the relay and reader use and whether the door stays open permanently are set in the UI. The LED ring on the reader gets its own animation per state: idle, open, rejected, held open.

Hardware settings: relay hold time, reader pins, permanent unlock and LED animations

Architecture

The reader at the door is an ESP8266 with an NFC module. It talks to the controller over UART by cable or, where there is none, over Wi-Fi. The controller is an ESP32 running FreeRTOS; it decides on access and switches the relay for the door opener.

A backend (Node.js, web UI in Svelte) manages members and cards. The controller polls it for changes at intervals — over Wi-Fi or an LTE modem — sending only the date of its last state. The answer is a small delta, binary with Protobuf (nanopb) over HTTP, so a cheap data SIM is plenty.

Hardware

The boards are etched and assembled by hand.

The controller

The board carries an ESP32 board, a real-time clock with a coin cell for the entry timestamps, a voltage converter and the relay for the door opener. The display on the left is still attached in the photo; it has since been removed. The board sits in a printed case.

Controller board with ESP32, real-time clock, voltage converter, relay and the display that has since been removed

The controller in its open case, next to the lid with the window for the display

The reader

The reader consists of an NFC module (RC522) with an ESP8266 on a hand-etched board behind it, both on a printed base. The ESP8266 reads the card, drives the RGB LED on the back and sends the number to the controller over UART; power and two wires are all it needs.

Reader from the side: RC522 NFC module with the ESP8266 on an etched board behind it; next to it the back with the RGB LED

In the test setup the reader glows in its case, with a card and a key fob in front. On the right the controller, its display showing its own Wi-Fi.

Test setup: reader in its case with the LED lit, card and key fob, the controller with display on the right

The first prototype

In the beginning a single ESP8266 did everything. The reader sat about two metres away and needed so many lines that a network cable carried them — hence the RJ45 jack. Today the same run uses UART.

First prototype from above with relay and RJ45 jack for the reader cable, next to the etched underside

An experiment: the keypad

The keypad was an early experiment and never made it to the door, as it added little. It was still instructive: an IO expander in the module scans the keys, so four lines are enough instead of one per row and column.

Keypad in a printed case with digits, confirm, cancel and two LEDs

The story of the data

At first the full member list lived on the device as a CSV file. That was slow, as measuring showed. Index structures would have helped but cost memory again. The breakthrough came from questioning the requirement: to decide at the door, a sorted index of valid cards is enough. A hit means access.

The server now builds that index; the device only stores it and finds a card by binary search within microseconds. The device records each entry with a timestamp (RTC module) and reports it to the backend, where the full log is kept. The result: fast decisions, small updates and no personal data on the hardware in the hallway.

Fallback and lessons

For emergencies the device ships a small web UI: firmware updates over Wi-Fi (OTA) and maintaining allowed cards over a direct connection.

The main lesson was to limit complexity. A display and keypad with their own menu layer added little in practice: the keypad never made it to the door, and I removed the display again. I put the time into the web UI and the data structures instead.