Roboelectrixx

RFID and Password Based Door Lock System Using Arduino

RFID and Password Based Door Lock System Using Arduino

tep by step guide for RFID and Password based door lock system using Arduino

Generally, the Basic requirement of security can be done by using mechanical electric door locks. Now, in this digital world, we are using various digital technology. For example, identification of digital device using cards or token, door lock system using digital technology, automatic door opening and closing etc. Nowadays, in most hotels, you can see RFID Door Lock Mechanism where you don’t need a key to unlock the room. This kind of systems used for controlling the movement of a door without using a key. This article represents the RFID and Password based Door Lock system. 

Components Required for Door lock system

Working Of Door Lock System

The RFID reader communicates with the Arduino through the SPI protocol and different Arduino boards have different SPI pins. Here, we are using RFID Reader/Writer RC522 SPI S50 with RFID Card.

The 16*2 Parallel LCD Display with Blue Backlight is interfaced with Arduino Mega to show the message. Here, we are using 4*4 matrix keypad to enter the password for door opening. In this prototype, we are operating the 12V door lock solenoid through the relay.

  • After, doing all the connection properly and upload the code. It will ask for scanning the card/tag and ask for the set password.
  • On scanning the wrong tag or on entering the wrong password, it will show the message of wrong input.
  • On scanning the right tag and entering the right password, it will send us a confirmation message that the door has opened.

Pin Connection of the components with Arduino

1. Connection of RFID reader with Arduino Mega

Connection of RFID sensor with arduino Mega

Connect the MFRC522 module with the Arduino Mega as per the below pin connections. Different Arduino’s have different SPI pins. If you are using different Arduino, then make connections according to that.

RC522 Reader- Uno/Nano- MEGA

  • SDA- D10- D9
  • SCK – D13- D52
  • MOSI- D11- D51
  • MISO- D12- D50
  • IRQ- N/A- N/A
  • GND- GND- GND
  • RST- D9- D8
  • 3.3V- 3.3V- 3.3V

2. Connection of LCD with Arduino Mega

Connection of LCD  with arduino Mega

We are interfacing the LCD1602 with Arduino using the data pins of the LCD module. The same connection and circuit will work for all Arduino and compatible boards. Connect the circuit as per the below connection,

  • VSS (0V)- Ground potential- Gnd
  • VDD (5V)- Positive Voltage
  • V0 (Contrast)- Contrast adjustment (used 10K pot)
  • RS- Register select (Instruction select-0 and Data select-1)- 
  • R/W- Read/write (Read-0 and Write-1)-
  • E- Enable pin
  • D4- A10
  • D5- A11
  • D6- A12
  • D7- A13
  • LCD +A- 5V
  • LCD-K- Gnd

3. Connection of Keypad of Arduino Mega

Connection of Keypad with arduino Mega

 The 4X4 keypad has 8 connections but we don’t require the last column and row of the keypad. We only require 3X3 keypad for the password. So we won’t use the PIN 4 and 8 of the keypad. You can also use 4X3 keypad instead of 4X4 and 3X3 keypad.

  • 1st pin- A0
  • 2nd pin- A1
  • 3rd pin- A2
  • 5th pin- A3
  • 6th pin- A4
  • 7th pin- A5

4. Connection of Relay and Door lock solenoid with Arduino Mega

Connection of Relay and Door lock solenoid with arduino Mega

Here, we are using a 5V relay module. It has 3 inputs and they are,

  • Vcc-Vcc
  • Gnd- Gnd
  • Signal- 49 (Active High)

And connect the 12V Door lock solenoid to the output of the relay module.

Software and Programming

Download the Arduino IDE Software and the required library for this code from the below links,


// Include required libraries
#include <MFRC522.h>
#include <Keypad.h>
#include <SoftwareSerial.h>
#include <SPI.h>
// Create instances
MFRC522 mfrc522(53, 5); // MFRC522 mfrc522(SS_PIN, RST_PIN)
// include the library code:
#include <LiquidCrystal.h>

 

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = A8, en = A9, d4 = A10, d5 = A11, d6 = A12, d7 = A13;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#define Doorrelay 49

 

char initial_password[4] = {'1', '2', '3', '4'};  // Variable to store initial password
String tagUID = "19 47 64 C1";  // String to store UID of tag. Change it with your tag's UID
char password[4];   // Variable to store users password
boolean RFIDMode = true; // boolean to change modes
boolean NormalMode = true; // boolean to change modes
char key_pressed = 0; // Variable to store incoming keys
uint8_t i = 0;  // Variable used for counter
// defining how many rows and columns our keypad have
const byte rows = 3;
const byte columns = 3;
// Keypad pin map
char hexaKeys[rows][columns] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'}
 
};
// Initializing pins for keypad
byte row_pins[rows] = {A0, A1, A2};
byte column_pins[columns] = {A3, A4, A5};
// Create instance for keypad
Keypad keypad_key = Keypad( makeKeymap(hexaKeys), row_pins, column_pins, rows, columns);
void setup() {
  Serial.begin(9600);
  pinMode(Doorrelay, OUTPUT);
  Serial.println("Scan your tag......... ");
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("WELCOME");
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Scan ur TAG");

}
void loop() {
  
 if (NormalMode == true) {
    // System will first look for mode
    if (RFIDMode == true) {
      // Function to receive message

 

      // Look for new cards
      if ( ! mfrc522.PICC_IsNewCardPresent()) {
        return;
      }
      // Select one of the cards
      if ( ! mfrc522.PICC_ReadCardSerial()) {
        return;
      }
      //Reading from the card
      String tag = "";
      for (byte j = 0; j < mfrc522.uid.size; j++)
      {
        tag.concat(String(mfrc522.uid.uidByte[j] < 0x10 ? " 0" : " "));
        tag.concat(String(mfrc522.uid.uidByte[j], HEX));
      }
      tag.toUpperCase();
      //Checking the card
      if (tag.substring(1) == tagUID)
      {
        Serial.println("Tag mached. ");
        Serial.println("Enter Password");
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("TAG matched");
        delay(2000);
        lcd.clear();
        lcd.print("Enter Password:");
        lcd.setCursor(0, 1);
        RFIDMode = false; // Make RFID mode false
      }
      else
      {
        Serial.print("Wrong Tag Shown");
        Serial.println("  Access Denied ");
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Wrong Tag Shown");
        lcd.setCursor(0, 1);
        lcd.print("Access Denied");
        delay(3000);
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Scan Your Tag   ");        
        
      }
    }
    // If RFID mode is false, it will look for keys from keypad
    if (RFIDMode == false) {
      key_pressed = keypad_key.getKey(); // Storing keys
      if (key_pressed)
      {
        password[i++] = key_pressed; // Storing in password variable
        lcd.setCursor(0, 1);
        lcd.print("****");
      }
      if (i == 4) // If 4 keys are completed
      {
        delay(200);
        if (!(strncmp(password, initial_password, 4))) // If password is matched
        {
          Serial.print("Password Accepted");
          lcd.clear();
          lcd.print("Pass Accepted");
          digitalWrite(Doorrelay, LOW);
          
          
          lcd.clear();
          i = 0;
          RFIDMode = true; // Make RFID mode true
        }
        else    // If password is not matched
        {
          Serial.println("Wrong Password");
          lcd.clear();
          lcd.print("Wrong Password");        
          delay(5000);
          
          lcd.clear();
          i = 0;
          RFIDMode = true;  // Make RFID mode true
        }
         
          digitalWrite(Doorrelay, HIGH);
          lcd.setCursor(0, 0);
          lcd.print("Scan ur TAG");
      }
    }
  }
}

Now, you can see the output in the below GIF.

  • Scanning of your tag
scanning of tags
  • Enter the correct passward, Door will be opened.
Door is opened

Hope this tutorial helps you to learn about the RFID and Password based Door Lock system. You can easily make the security for your home with the reference of this tutorial so let’s hurry up!