Lessons and the learning game

Build a smart lock

A keypad, a card reader and a fingerprint sensor guarding a 12 V bolt: how locks think, with honest notes on what makes them strong or weak.

What you build

A lock that opens a solenoid bolt for a code, a card or a finger, and in the end only for all three together. It hides the code, checks it in constant time, logs every attempt to EEPROM and locks out guessers.

A hobby lock is a way to learn how locks think, not a certified lock. Never fit one where it could shut a person or a pet in, and always keep a mechanical way out.

How it works

Codes done right. Digits show as stars, never echoed. The check compares every digit before deciding, so a wrong guess takes the same time wherever it is wrong: a constant-time compare.

A latch that fails secure. The relay puts 12 V on the solenoid for three seconds; the bolt springs back when the power goes. A fail-safe lock does the opposite, as fire codes require on escape routes.

RFID, honestly. The reader gets a card's UID with no secret at all, and cards with rewritable UIDs are cheap. A UID is a name, not a password.

Fingerprints. The sensor matches the finger against its own library and reports a number. Strong, but not unbeatable.

Logs and lockouts. A ring of 16 events in EEPROM survives power cuts. Three wrong codes lock out for 30 s, then 60, then 120.

Three factors. Something you have, something you are, something you know, in order and in time.

The course

Build a smart lock has six lessons, all on the same wiring:

  1. Keypad codes: hidden digits and a constant-time compare.
  2. The latch: a relay, a solenoid, fail secure and fail safe.
  3. RFID cards: UIDs and why they are weak.
  4. Fingerprint: a sensor that does its own matching.
  5. Logs and lockout: an EEPROM ring and doubling lockouts.
  6. Project: a three-factor door: card, finger, code.

Every step is checked against the running circuit, apart from the last, where you make the lock your own and share it.