RFID Door Locks

Can You Build an RFID Door Lock With Arduino?

Yes, you can build an RFID door lock with an Arduino. Here are the parts, wiring approach, code logic and the security limits to know before mounting it on a door.

On this page
  1. Yes, with some caveats
  2. Parts you’ll need
  3. How the pieces fit together
  4. How the code works
  5. Making it reliable enough to live on a door
  6. Security limits of a DIY build
  7. Good uses for a DIY RFID lock

Yes, with some caveats

You can use an Arduino to create an RFID door lock, and it’s one of the most popular beginner and student electronics projects. A low-cost RFID reader module reads a card or fob, the Arduino checks the ID against a list of approved cards, and if it matches, it switches on a solenoid lock or electric strike for a few seconds.

The caveat is security. A basic build is a great way to learn how card locks work, and it’s fine for a cabinet, a workshop door or a project box. It’s not a drop-in replacement for a properly installed commercial lock on an exterior door, for reasons covered further down.

Parts you’ll need

A typical build uses:

  • An Arduino board. An Uno or Nano is common. An ESP32 or similar board is a popular alternative if you want Wi-Fi.
  • An RFID reader module. The MFRC522-based module, which reads 13.56 MHz cards such as MIFARE tags, is widely used and often sold with a card and a fob. There are also 125 kHz reader modules for older proximity cards.
  • Cards or fobs that match the reader’s frequency.
  • A lock mechanism. Usually a 12 V solenoid bolt lock, or a 12 V electric strike for a real door frame.
  • A switching device. A relay module or a logic-level MOSFET, because the Arduino can’t power the lock directly.
  • A flyback diode across the solenoid coil if your switching module doesn’t already include one.
  • A power supply. Commonly a 12 V DC adapter sized for the lock’s current draw, plus a way to supply the Arduino (a regulator, or the board’s own input if it accepts 12 V).
  • Optional extras: a buzzer, red and green LEDs, an inside exit button, a door sensor, and a small LCD or OLED display.

How the pieces fit together

Wiring the reader

The MFRC522 module talks to the Arduino over SPI, which uses a handful of pins (data in, data out, clock and chip select) plus a reset pin. Importantly, the MFRC522 is a 3.3 V device. Power it from the Arduino’s 3.3 V pin, not 5 V. Many hobbyists connect its data lines directly to a 5 V Uno and it often works, but a level shifter is the safer approach.

Driving the lock safely

A solenoid lock draws far more current than an Arduino pin can supply, so the pin only controls a relay or MOSFET, and that switch connects the lock to the 12 V supply.

Two points are easy to get wrong:

  • Flyback protection. When a solenoid switches off, its coil produces a voltage spike. A diode across the coil, oriented to block normal current, gives that spike somewhere safe to go. Without it, you risk resets or damaged components.
  • Duty cycle. Many cheap solenoid locks are designed to be energized only briefly. Holding them on for long periods can overheat them. Short unlock pulses of a few seconds are typical.

Powering the build

Keep the lock’s power path separate from the logic as much as possible, with the grounds connected. Solenoids can cause voltage dips when they fire, which may reset the Arduino if both share a weak supply. A decent adapter and, if needed, a capacitor near the board help.

How the code works

Most sketches use a widely available MFRC522 library and follow the same logic:

  1. Setup. Start SPI, initialize the reader, set the lock pin as an output and make sure it starts locked.
  2. Wait for a card. In the main loop, check whether a new card is present and read its UID (unique identifier).
  3. Compare. Check the UID against a list of authorized IDs, either hard-coded for a first test or stored in the board’s EEPROM so you can add cards later.
  4. Act. If it matches, light the green LED, beep and energize the lock for a few seconds, then lock again. If not, show red and log or ignore the attempt.
  5. Enrollment (optional). Use a “master” card that puts the system into add or remove mode, so you don’t have to reprogram the board to change users.

Adding a short delay or “lockout” after several failed reads is a sensible touch, as is a debounce so one tap doesn’t trigger twice.

Making it reliable enough to live on a door

If you’re going beyond a bench test:

  • Plan for power loss. Decide whether the door should stay locked or unlock if power fails. A solenoid bolt that springs out when unpowered keeps the door locked; a maglock releases. Make sure there’s always a way out from the inside, such as a mechanical handle or an exit button wired so it works independently of the code.
  • Keep the brains inside. Put the Arduino, relay and power supply on the secure side of the door, with only the reader on the outside. Otherwise someone could open the enclosure and short the lock wires.
  • Add a fallback. A mechanical key, a hidden override or a battery backup avoids being locked out by a crash or a dead adapter.
  • Use a watchdog. The microcontroller’s watchdog timer can restart the board if the code hangs.
  • Protect the enclosure. Dust, moisture and temperature swings are hard on hobby modules, so outdoor readers need a weatherproof housing.

Security limits of a DIY build

The most common Arduino approach, checking only the card’s UID, has a fundamental weakness: the UID isn’t secret. Cards and tags exist whose UID can be changed, and inexpensive tools can read and copy the UID of a card. So a lock that trusts the UID alone is relatively easy to fool for someone who knows what they’re doing.

More secure builds use encrypted card types and check data protected by keys rather than just the UID, but doing that properly takes a fair bit more work. On top of that, a hobby build lacks the tamper resistance, tested hardware and fire-code considerations of commercial products. For background on card types and their weaknesses, see our explanation of what RFID is used in locks, and for the wider trade-offs, what are the disadvantages of electronic locks.

Good uses for a DIY RFID lock

  • Learning projects and school or college electronics assignments
  • Cabinets, toolboxes, drawers and lockers
  • Workshop, garage or hobby room doors where convenience matters more than high security
  • Prototyping before buying or specifying a commercial system

If you want a card lock on your front door, a commercial RFID or smart deadbolt is usually the more sensible choice, and our guide on how to automate a door lock covers ready-made options. To understand how the professional systems you’d be imitating are put together, see our overview of how an RFID door lock system works.

The complete guide to rfid door locks

How an RFID Door Lock System Works
Read the guide

Keep exploring

Guides from other topics

All topics →