Skip to main content

Arduino RFID Door Lock System with Solenoid Lock & Keypad

In the previous RFID projects, we learned how RFID works and built a basic access control system.

Now we will take the next step and build a real electronic door lock system similar to those used in offices, labs, and smart homes.

This version introduces:
  • A real electromagnetic door lock
  • Secondary authentication using a keypad
  • Proper power switching using a MOSFET/relay
  • Security-focused design considerations

Learning Objectives

By completing this tutorial, you will learn how to:
  • Authenticate RFID cards using Arduino
  • Add a keypad for two-factor authentication
  • Safely control high-power loads (electromagnetic lock)
  • Design fail-safe embedded security logic
  • Understand how real access control systems work

Watch Project Overview

How the System Works

This project implements a two-step authentication process:
  1. RFID card is scanned
  2. User enters a PIN on keypad
  3. If both are correct → door unlocks
  4. If not → alarm and access denied
This mimics real-world office and hotel door security systems.

Components Required

  • Arduino Uno - Main Controller
  • MFRC522 RFID Module - Reads RFID cards & tags
  • Electromagnetic lock (12V) - Physical door lock
  • 4x4 Keypad - PIN Authentication
  • Relay Module / MOSFET - Switches the lock safely
  • External 12V power supply - Powers the lock
  • Buzzer - Alarm
  • Red/ Green LEDs - Status indicators

Safety and Power Requirements

This project uses a 12V electromagnetic lock, which draws much more current than Arduino can provide.
Important safety rules:
  • NEVER power the lock from Arduino 5V
  • Always use an external 12V power supply
  • Use a relay or MOSFET to switch the lock
  • Place a diode across the lock terminals to prevent back-EMF damage
This is essential in real embedded hardware design.

Why Use a Relay or MOSFET?

Arduino pins provide only small current. 
The lock requires high current at 12V.
The relay/MOSFET acts as an electronic switch:
  • Arduino sends small control signal
  • Switch controls large lock current safely
This is a key concept in embedded power electronics.

Wiring Overview

RFID → Arduino (SPI)

MFRC522 Pin

            Arduino

SDA            D10
SCK            D13
MOSI            D11
MISO            D12
RST            D9
GND            GND
3.3V            3.3V

Keypad Connections

Keypad Pin

            Arduino

R1–R4            D2–D5
C1–C4            D6–D9

Lock and Feedback Devices

Device

            Arduino Pin

Relay/MOSFET            D3
Green LED            A0
Red LED            A1
Buzzer            A2

Authentication Logic

The system follows this decision process:
  1. Wait for RFID card
  2. Check if UID is authorized
  3. Ask for PIN via keypad
  4. If PIN correct → unlock door
  5. Else → trigger alarm
This layered logic improves security significantly.

Code Snippet

Code Explanation

RFID Authentication

The system first checks whether the scanned UID matches an authorized user.

Keypad Verification

If RFID is valid, the user must enter a correct PIN.

Unlock Sequence

When both conditions are satisfied:
  • Relay activates
  • Lock releases
  • Green LED turns on
  • Buzzer beeps once

Alarm Sequence

If authentication fails:
  • Red LED turns on
  • Buzzer sounds repeatedly
  • Door remains locked

Testing the System

Successful Access

  • Scan authorized card
  • Enter correct PIN
  • Door unlocks for a few seconds

Failed Access

  • Wrong card OR wrong PIN
  • Alarm sounds
  • Door remains locked

Security Discussion

This system demonstrates multi-factor authentication:
  • Something you have → RFID card
  • Something you know → PIN code
Professional systems also include:
  • Encrypted RFID cards
  • Event logging
  • Network monitoring
  • Backup power systems

Troubleshooting

RFID not detected

  • Ensure module is powered with 3.3V
  • Check SPI wiring carefully

Lock not activating

  • Check external power supply
  • Verify relay wiring and diode polarity

Keypad inputs incorrect

  • Verify row/column pin mapping

Conclusion

You have built a complete RFID-based smart door lock system with two-factor authentication. This project combines RFID identification, keypad verification, actuator control, and safety-focused power design into one practical embedded system.

The concepts used here form the foundation of modern access control systems used in workplaces, laboratories, and smart homes. From this point, you can expand the system into a connected IoT security platform with logging, remote monitoring, and mobile integration.

Frequently Asked Questions

Can I add multiple users?

Yes. Store multiple UIDs and PIN codes in arrays or external memory.

Can this run during power failure?

Add a battery backup or UPS for real installations.

Can I use a solenoid lock instead?

Yes. The wiring remains the same; only voltage/current ratings change.

Is RFID secure?

Basic UID cards can be cloned. Advanced systems use encrypted cards.

Comments

Popular posts from this blog

Arduino Serial Communication Beginner Guide (UART Explained)

Serial communication is the backbone of most Arduino projects. It allows your Arduino to talk to your computer, Bluetooth modules, Wi-Fi modules, sensors, and even other Arduinos. If you have ever used the Serial Monitor, you have already used serial communication - now you will understand how it really works. By the end of this guide, you will learn: What serial communication is What UART means How Arduino communicates with devices How to send and receive data How baud rate works Common mistakes beginners make What is Serial Communication? Serial communication is a method of sending data one bit at a time over a single wire. Instead of sending many bits simultaneously (parallel communication), serial sends bits sequentially: Example: The letter A in binary = 01000001 These bits are sent one after another very quickly. This method is: Simple Reliable Perfect for microcontrollers What is UART? UART stands for: Universal Asynchronous Receiver Transmitter It is the hardware ins...

How to Connect HC-06 Bluetooth Module with Arduino (Step-by-Step Beginner Guide)

Bluetooth communication is one of the easiest ways to make Arduino projects wireless. Once you understand how to use a Bluetooth module, you can build robots, home automation systems, and smartphone-controlled devices. In this tutorial, you will learn how to interface the HC-06 Bluetooth module with Arduino and send data wirelessly using your phone.    By the end of this guide, you will be able to: Understand how the HC-06 Bluetooth module works Configure the module using AT commands Safely connect it to an Arduino Send and receive serial data over Bluetooth Build the foundation for wireless Arduino projects Watch the Project Overview What is the HC-06 Bluetooth Module? The HC-06 is a Bluetooth-to-Serial module designed to add wireless communication to microcontrollers such as Arduino. It uses Bluetooth 2.0 (SPP - Serial Port Protocol), which means it behaves like a wireless serial cable. Whatever is sent from the phone appears in Arduino’s Serial Monitor and vice versa. ...

How to Use SoftwareSerial on Arduino (Connect Multiple Serial Devices)

In the previous tutorial, you learned how Arduino uses hardware serial communication through pins 0 (RX) and 1 (TX). That built-in serial port is mainly used to communicate with your computer through the USB cable and Serial Monitor . But here is the problem beginners quickly face: Many popular modules use serial communication, such as: Bluetooth modules ( HC-05 / HC-06 ) GPS modules GSM modules Wi-Fi modules ( ESP8266 ) Arduino Uno has only one hardware serial port. So how can we connect these modules while still using the Serial Monitor? The solution is SoftwareSerial . In this tutorial you will learn how to create additional serial ports using normal digital pins. By the end, your Arduino will be able to talk to multiple serial devices. What is SoftwareSerial? SoftwareSerial is a special Arduino library that allows digital pins to behave like RX and TX pins. This means Arduino can create extra serial ports using software instead of hardware. Hardware Serial vs Software Seri...