DIY RFID Door Lock System Using Arduino

by Yogeshwaran in Circuits > Arduino

557 Views, 10 Favorites, 0 Comments

DIY RFID Door Lock System Using Arduino

6-5 ratio (Title-RFID Door Locking System).png

Have you ever seen those cool card-swipe door systems in offices and wondered how they work? Well, you can create your own RFID-based door lock system using an Arduino, an RFID reader, and a solenoid lock. All from the comfort of your home! This project is simple, affordable, and a great way to dive into the world of smart home automation.

If you want to know detailedly, how to make RFID Door lock using Arduino, check there where I explained everything from top to bottom.

Supplies

Parts (Web).png
  1. Arduino UNO R3 Development Board
  2. RC522 RFID Reader
  3. RFID Cards or Tags
  4. Solenoid Door Lock
  5. Single Channel Relay Module
  6. 16x2 I2C LCD Display
  7. Jumper Wires
  8. Power Supply Adaptor

Draw Circuit Diagram for Arduino RFID Door Lock System

Circuit Diagram.png

The above RFID Door Lock System circuit diagram represents how an Arduino, RFID Module, Relay module, Solenoid Lock, and LCD display are connected to create a secure and automated door lock system.

If you are a passionate hardware guy, just jump here, where I explained the working of this Arduino RFID Door Circuit Diagram in clear way.

Still get confused with the wiring connection like, In which pin do I want to connect which one? No worries, check out Pinout Connection Tabulation, where I mentioned one to one pinout connection in easily understandable way.

Make Your Hands Get Dirty While Setting Up Our Hardware

Parts marking with wires (Web).jpg

For complete video guide for setup and working demonstration, check out this link - https://www.youtube.com/watch?v=PeGIjCImpE0

As you can see the hardware connections are pretty easy and straightforward. This set-up is powered buy a 12V lithium battery pack making the project portable and easy to install, For practical purpose, you can opt for 12V adapter.

We have built a lot of RFID based projects previously, if you are completely new RFID and would like to understand the basics of RFID and how it works with Arduino you can read our Arduino RFID tutorial before proceeding with this project.

Write Some Code for Our Arduino RFID Door Lock System

DEMO-1.jpg
DEMO-2.jpg
rfid_code_upload-1.jpg

Before moving on to this below code that I provided, you first want to know about the yours Authorized RFID Tag UID value. Which is essential, so that our RFID Door lock can distinguish the Authorized RFID Tag from the group of unauthorized RFID Tags.

To get to know the UID details of your Authorized RFID Tag, check this RFID Tag UID Scan Code. After dumping this RFID UID Scan code, you can able to see the scanned RFID Tag UID values on the Serial monitor as well as in the Display as shown in the above images. Just copy that UID value and replace it on the below code's "byte authorizedUID[] = {0x69, 0xA9, 0x81, 0x5A}; " Variable as shown in the above image.


This is the actual main code for our RFID Door Lock System, just make sure that you replace the UID with your Authorized Tag UID value in it. If you want step by step walkthrough of RFID Door Lock code, check there.


#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>

// Define RC522 pins
#define RST_PIN 9
#define SS_PIN 10

// Relay pin
#define RELAY_PIN 8

// Initialize MFRC522 instance
MFRC522 rfid(SS_PIN, RST_PIN);

// Initialize LCD (address 0x27 may vary)
LiquidCrystal_I2C lcd(0x27, 16, 2);


// Authorized UID (replace with your tag's UID)
byte authorizedUID[] = {0x69, 0xA9, 0x81, 0x5A};

// Door status
bool doorLocked = true;

void setup() {
// Initialize SPI and RC522
SPI.begin();
rfid.PCD_Init();

// Initialize LCD
lcd.init();
lcd.backlight();

// Set up relay pin
pinMode(RELAY_PIN, OUTPUT);

// Display startup message
lcd.setCursor(0, 0);
lcd.print("RFID Door Lock");
delay(2000);
lcd.clear();
lockDoor(); // Start with door locked
}

void loop() {
// Check if a new RFID card is present
if (!rfid.PICC_IsNewCardPresent()) {
return;
}

// Check if the RFID card can be read
if (!rfid.PICC_ReadCardSerial()) {
return;
}

// Display scanned UID
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Scanning...");
delay(2000);

// Compare scanned UID with authorized UID
if (isAuthorized(rfid.uid.uidByte, rfid.uid.size)) {
lcd.setCursor(0, 1);
lcd.print("Access Granted!");
delay(2000);
unlockDoor(); // Lock or unlock the door
} else {
lcd.setCursor(0, 1);
lcd.print("Access Denied!");
delay(2000);
lockDoor();
}

// Halt communication with the card
rfid.PICC_HaltA();
}

// Function to check if UID matches authorized UID
bool isAuthorized(byte *uid, byte size) {
if (size != sizeof(authorizedUID)) {
return false;
}

for (byte i = 0; i < size; i++) {
if (uid[i] != authorizedUID[i]) {
return false;
}
}
return true;
}

// Function to lock the door
void lockDoor() {
digitalWrite(RELAY_PIN, LOW); // Turn OFF relay (lock engaged)
doorLocked = true;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Door Locked");
delay(2000);
}

// Function to unlock the door
void unlockDoor() {
digitalWrite(RELAY_PIN, HIGH); // Turn ON relay (unlock door)
doorLocked = false;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Door Unlocked");
delay(10000); // Keep door unlocked for 5 seconds
lockDoor(); // Auto-lock after 5 seconds
}



Upload the Above Code Into Arduino

rfid_code_upload-1.jpg

After replacing the "byte authorizedUID[] = {0x69, 0xA9, 0x81, 0x5A}; " with your's authorized RFID Tag UID Value. Lets dump the above code into your Arduino.

If you face any issue, while dumping the code into Arduino.Check this Arduino Troubleshooting Tutorial.

Lets Test Our RFID Door Lock System

DEMO-3.jpg
DEMO-4.jpg

At last, we've entered the most exciting phase, i.e final testing of our RFID Door Lock System using Arduino!. In the above images, you can see that, after scanning the Authorized RFID tag, it granted access and make the solenoid Door lock to get Unlocked.

No matter if you're a beginner or an experienced maker, this DIY RFID Door Lock System makes learning about RFID readers in both fun and simple. Ready to build your own?

Want to discover more cool projects? Dive into our collection of Arduino IoT Projects | Arduino Robotics Projects | Arduino AI Projects | Arduino Home Automation Projects | Raspberry Pi Projects | ESP32 Projects to inspire your next build!