RFID Based Door Lock System Using Arduino Uno & RFID RC522 Module

January 29, 2022



Description

Hello, In today's article I will show you How To Make RFID Based Door Lock System Using Arduino Uno & RFID RC522 Module. We also place a push button inside the room to open the door from inside. Today you can see different types of Door locks are available in the market for example. Biometric Door Locks, Password-based Door lock, RFID Based Door Locks & in this article I'll explain to you how to make RFID Based Door Lock. You have seen this type of lock-in hotel room where you need to put an RFID card over the lock & it opens the lock. Do you know that?  For your information did you know that each & every RFID card has its unique ID, you will not get cards with the same unique ID, so no other person can open the door lock with another card. The Doorlock will get open when you put a Registered RFID card over the RFID Reader. You can register many Cards to the system but we will make that project after this project. So in this project for lock purpose we use an electronic lock means A Solenoid lock that lock & Unlocks while providing a 12V DC supply. You know that old-fashioned mechanical lock breaks & there are chances of robbery, so avoid this we make this project where the door will open when we use the registered card to unlock. I have already made a complete project by making a video on Youtube you can refer to this video for better understanding.

Watch out the video If reading bores you.

If you got this article helpful, subscribe to our blog and our Youtube Channel for more interesting projects.

Material Required:-

[Following links are affiliated links, If you buy from them, We get some bonus from it.]

Sr.No

Product Name

Quantity

Best Buy Link

1

Arduino Uno

1

https://amzn.to/3AiCiWD

2

RFID Module (RC522)

1

https://amzn.to/3KyZwfF

3

I2C LCD Display

1

https://amzn.to/3Kog1Lw

4

Resistor (470E & 1K)

2, 1

https://amzn.to/3Ig0N9E

5

Solenoid Lock

1

https://amzn.to/33vDmup

6

Push Button

1

https://amzn.to/3rVIC2D

7

LED (Red & Green)

2

https://amzn.to/3FMui1e

8

Breadboard + Jumper Wires

1

https://amzn.to/33vHkmM

9

1-Channel Relay Module

1

https://amzn.to/3rFuwSy

10

12V Adapter

1

https://amzn.to/3nGRcAM

11

LM2596 Module

1

https://amzn.to/33vxWzv

I provide the best buy link for components, Here you will get the best quality of projects. Do check it out.

Circuit Diagram:-

RFID Based Door Lock System Using Arduino Uno & RFID RC522 Module

Refer above Circuit Diagram to make connections on the breadboard.

RFID Module:-

RFID Based Door Lock System Using Arduino Uno & RFID RC522 Module

In this project, we are using the RFID RC522 module to interface with Arduino.RFID stands for Radio Frequency Identification Technology. This module is divided into two-part means RFID Reader & RFID Card, there is also an RFID Key chain are available. These tags are specially designed to generate up to 13.56MHz of electromagnetic field & this electromagnetic field gets read/detect by the RC522 RFID module. This module works on 3.3V DC Supply hence it's compatible with Arduino because there are 3.3V available on Arduino. Each RFID Tag/Card has its unique ID. We can use this system in Identification System, Acces Control Systems, Automatic billing system in the supermarket we can also use this system in colleges & school for Attendance purpose.

Pinouts Of RFID RC522 Module:-


RFID Based Door Lock System Using Arduino Uno & RFID RC522 Module

Refer above image to understand the Pinouts of this module.


Note:- Do not supply this module with a 5V Supply, It will damage the module.

Working of the project:- 

To operate the lock using an RFID Card first we need to add the card into the system, for that we need to upload the Arduino code to the Arduino. Then scan the card which you won't use as a key. Open serial monitor in Arduino IDE then scan the card then you will get the unique ID of that card in serial monitor then copy that ID & paste it into the code. Replace the "6A 7F 65 B3" ID with your card ID.

RFID Based Door Lock System Using Arduino Uno & RFID RC522 Module

Then upload code again. Now you can unlock the Electronic lock using an RFID Card. You just need to scan the card on RFID Module if the card is registered with Arduino then it opens the lock for you. If you can with an unregistered card then the system does not allow you to open the lock. This means other peoples cant open the lock without a registered card, hence this system will help you to enhance your safety. The chances of robbery will be zero.

Arduino Library:-

[ To perform this project first we need to add the following libraries in your Arduino IDE. ]

1.Wire.h
2.SPI.h
3.MFRC522.h
4.LiquidCrystal_I2C.h

Follow the same steps to add all libraries in Arduino IDE:-

RFID Based Door Lock System Using Arduino Uno & RFID RC522 Module

Open Sketch >> Include Library >> Manage libraries.

RFID Based Door Lock System Using Arduino Uno & RFID RC522 Module

Just search for the above-listed libraries & install them in your Arduino IDE.

Arduino Code:-

/*
 * Hello guys welcome back to "Techno-E-Solution"
 * Project Name:- RFID Based Door Lock System Using Arduino Uno & RFID RC522 Module
 * Project Video:- https://www.youtube.com/watch?v=mmF7q6Nuj6Y&t=2s
 * Here is the code for this project
 */
#include <Wire.h>
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h> 
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Before uploading the code First install the above Libraries in your Arduino IDE
 
#define SS_PIN 10
#define RST_PIN 9
#define LED_G 4 // Green LED pin
#define LED_R 5 // Red LED pin
#define lock 3
MFRC522 mfrc522(SS_PIN, RST_PIN);
int Btn = 6;
 
void setup() 
{
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  pinMode(LED_G, OUTPUT);
  pinMode(LED_R, OUTPUT);
  pinMode(Btn,INPUT);
  pinMode(lock,OUTPUT);
  Serial.println("Place your card on reader...");
  Serial.println();
  lcd.init();
  lcd.backlight();
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" Scan Your RFID "); 
  lcd.setCursor(0,1);
  lcd.print("   Door Locked   ");
 }
void loop() 
{
if(digitalRead(Btn) == HIGH){
  
    Serial.println("Access Granted");
    Serial.println();
    delay(500);
    digitalWrite(LED_G, HIGH);
    lcd.setCursor(0,1);
    lcd.print(" Door Un-Locked ");
    digitalWrite(lock,HIGH);
    delay(3000);
    digitalWrite(lock,LOW);
    delay(100);
    digitalWrite(LED_G, LOW);
    lcd.setCursor(0,1);
    lcd.print("   Door Locked   ");
  }

  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();

  
 if (content.substring(1) == "6A 7F 65 B3") //change here the UID of card/cards or tag/tags that you want to give access
  {
    Serial.println("Access Granted");
    Serial.println();
    delay(500);
    digitalWrite(LED_G, HIGH);
    lcd.setCursor(0,1);
    lcd.print(" Door Un-Locked ");
    digitalWrite(lock,HIGH);
    delay(3000);
    digitalWrite(lock,LOW);
    delay(100);
    digitalWrite(LED_G, LOW);
    lcd.setCursor(0,1);
    lcd.print("   Door Locked   ");
  }
else
{
    lcd.setCursor(0,1);
    lcd.print("Invalid RFID Tag");
    Serial.println(" Access denied");
    digitalWrite(LED_R, HIGH);
    digitalWrite(LED_R, LOW);
    delay(100);
    digitalWrite(LED_R, HIGH);
    delay(500);
    digitalWrite(LED_R, LOW);
    delay(100);
    digitalWrite(LED_R, HIGH);
    delay(500);
    digitalWrite(LED_R, LOW);
    lcd.setCursor(0,1);
    lcd.print("   Door Locked   ");
 }
 delay (100);
 }

You can Buy me a coffee If you got this article helpful.