Skip to Content
My workProjectsRFID based door lock using STM32 MCU

Building an NFC Door Lock

1. It All Started With… Losing My Keys (Again)

I’d been binge-watching embedded-systems YouTube channels and working through FastBit Academy courses when the universe handed me the perfect capstone assignment: I misplaced my hosue keys for the third time in a month.

Because I’d already seen countless demos of MCUs talking to RFID readers, I knew an NFC door lock was possible—and, more importantly, within reach of my current skill set. The project goal became clear: replace my metal keys with a simple tap-to-unlock experience using parts I could breadboard in a weekend.


2. Core Components

#PartReason to choose
1STM32F103C8 (“Blue Pill”)Affordable, plenty of community support, and I wanted to use something that is used in industry.
2MFRC522 RFID/NFC moduleHas a decent HAL driver in STM32CubeIDE.
3Relay module + optocouplerIsolates the door-strike circuit from MCU GPIO noise; safer than driving the relay transistor directly.
4Buck converterSteps 12 V wall-wart down to 5 V for the relay and 3.3 V LDO on the Blue Pill. Common, dirt-cheap, easy to tune.

3. Testing the components individually

Before wiring everything together I validated each part in isolation:

  1. STM32: Flashed the classic blink on the internal LED, then drove an external LED on PB13 to confirm the GPIOs were alive.
  2. RC522: Used the SWD debugger inside STM32CubeIDE to step through the HAL example and verified that MFRC522_GetVersion() did not return 0x00/0xFF.
  3. Relay: Toggled a GPIO high after a 3-second delay; multimeter and audible relay click confirmed isolation was working.

Once each module passed the test I wired them all on a single breadboard prototype and successfully tapped my metro card to light the relay.


4. Power: From Wall Wart to Clean 3.3 Volts

I settled on a 12 V/1 A barrel-jack adapter (spares from an old router). A buck converter tuned to 5 V feeds the STM32 board and relay module and the 3.3V pin connects to the RC522:

Lesson: Common ground is non-negotiable; floating grounds caused phantom reads on the RC522.


The circuit diagram

Circuit Diagram


5. From Breadboard Bliss to Perf-Board Purgatory

Breadboards make awful long-term door locks, so I migrated everything to a perf board… and that’s when the gremlins arrived:


Hurdle 1 - Novice at soldering

First-time soldering meant first-time destroying hardware: I overheated the RC522 while wicking a bridge and toasted the reader IC. Replacement parts took 3-4 days to arrive—ample time to binge more soldering tutorials.

Lesson → Use female headers on the perf board so fragile modules can be swapped instead of desoldered.

Hurdle 2 - The MCU is dead

While dry-fitting the assembly on the door frame I twisted the board, cracked a trace, and the STM32 never enumerated again. Another 3-4-day shipping timeout.

Silver lining: Thanks to the female headers, the fresh Blue Pill clicked in and the firmware ran on first power-up.

Hurdle 3 - The metal-door surprise

It finally dawned on me that a steel door is basically a Faraday cage. The reader’s range dropped to near-zero when mounted flush. Solution: split the system.

Outside (public side)Inside (secure side)
RC522 readerRelay module
STM32 (placed as close as possible—less than 10 cm SPI)Buck converter + door strike

SPI can’t tolerate long runs without shielding, so the MCU stays with the reader. A 4-core cable (3.3 V, GND, SPI CS/DATA) runs through the door edge to the relay supply.


7. Decoupling the Two Boxes

Once the metal-door revelation sunk in, I redrew the schematic as two separate boards: a front-end reader + MCU module mounted outside and a back-end power + relay module tucked safely inside.

Keeping the Old Wiring (Mostly) Intact

To avoid a full re-layout, I left the existing perf-board wiring in place wherever possible—snip, strip, and reroute only what absolutely needed moving. Fewer desoldering scars = fewer new mistakes.

How the Two Halves Talk

My first instinct was to run the four required lines (5V, GND, Relay Input) through an Ethernet patch cable. But with no RJ-45 female jacks on hand, I invoked Occam’s Razor and used what I had: female DuPont jumpers soldered to break-away header pins on both boards. Crimp, heat-shrink, done.

Is it elegant? Not really. Does it work? Absolutely—and the connector is field-replaceable if a wire snaps.

The Circuit Diagram

Circuit Diagram

8. Next Steps - From Prototype to Daily Driver

Over the next sprint, I’m focusing on three concrete milestones to transform this proof-of-concept into a reliable tap-to-unlock door system:

  1. Create Robust Enclosures

    • Use simple board to create enclosures for the two boxes
  2. Install the System

    • Mount the reader box on the exterior door surface
    • Route the 3-core jumper through the door-edge
    • Secure the indoor control box near the strike plate
  3. Integrate the Lock Mechanism

    • Connect the relay’s normally-open contacts to the electric strike circuit
    • Configure the system to energize the latch on authorized NFC taps

Stay tuned for the build-out and the glorious first tap-to-unlock!

Source Code

Last updated on