Arduino RFID door lock projects.

Mr.ElectroUino
0
Arduino RFID Door lock project.
Arduino rfid door lock projects


 Arduino RFID Door lock project.

Hello viewers! In this blog you will find out how to make door lock with RFID modules. 
rfid door lock arduino

 Component requirements: 

1. Arduino Uno
2. RFID MFRC522.
3. Servo Motor (SG90).
4. 16x2 LCD I2C display.
5. Buzzer.
6. LEDs    x    3.
7. Resistor (220om)   x   4
8. Breadboard.
9. Jumper Wires.

 Circuit Diagram for door lock projects: 

arduino rfid door lock projects
Circuit diagram for door lock.


Pin Connection:

1. Firstly, make a connection between the Arduino Uno and RFID 
MFRC522.
  • The Arduino pin 10 should be connected to the RFID SDA pin.
  • The Arduino pin 13 should be connected to the RFID SCK pin.
  • The Arduino pin 11 should be connected to the RFID MOSI pin.
  • The Arduino pin 12 should be connected to the RFID MISO pin.
  • The Arduino GND pin should be connected to the RFID GND pin.
  • The Arduino pin 9 should be connected to the RFID RST pin.
  • The Arduino 3.3v pin should be connected to the RFID VCC pin.
Note: Make sure that You connected RFID VCC pin to arduino 3.3v pin.
Don't connect it to 5v. It will damage the circuit of rfid sensor.

2. Now, Its time to connect the LEDs to the arduino.
  • The Led 1 positive pin is protected with a 220 ohm resistor, and the resistor end is attached to the Arduino pin 2. 
  • The Led 2 positive pin is protected with a 220 ohm resistor, and the resistor end is attached to the Arduino pin 3. 
  • The Led 3 positive pin is protected with a 220 ohm resistor, and the resistor end is attached to the Arduino pin 4.
  • Connnect negative pins of LEDs to arduino GND pin
In order to protect the LEDs, a 220 ohm resistor is used as a current limiter.

3.Buzzer connection to arduino.
  • Connect the  buzzer positive pin to pin 5 of the Arduino.
  • Connnect negative pins of buzzer to arduino GND pin
4. Now we have to make a connection between arduino and servo motor (sg90).
  • Connect the Servo pin to pin 6 of the Arduino.
  • Connect the Servo VCC pin to 5v pin of the Arduino.
  • Connect the Servo GND pin to GND pin of the Arduino.
5. Last component is 16x2 LCD display with I2C driver.
  • The Arduino A5 pin should be connected to the LCD SCL pin.
  • The Arduino A4 pin should be connected to the LCD SDA pin.
  • The Arduino 5v pin should be connected to the LCD VCC pin.
  • The Arduino GND pin should be connected to the LCD GND pin.
Now the circuit is completed. Lets jump to the coding part. 

 Coding: 

1. At first, we need to install the library for RFID sensor.
For that Open arduino software and goto Tool -> Manages libraries and search for MFRC522 and install the library.
2. Connect the Arduino uno to the PC using a USB cable for uploading the code.

2. Now, We have to get the master card ID to use it for unlock the door. For that we need to copy this code. This code provide us master card ID which we can use it later.
#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 9
#define SS_PIN  10

MFRC522 mfrc522(SS_PIN, RST_PIN);
String UIDCard = "";

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  Serial.println("Scan your RFID Card:");
  for (int i = 0; i < 20; i++) {
    Serial.print(".");
    delay(50);
  }
  Serial.println("");
}

void loop() {
  //Wait until new tag is available
  while (getUID())
  {
    Serial.print("UID: ");
    Serial.println(UIDCard);

    for (int i = 0; i < 20; i++) {
      Serial.print(".");
      delay(50);
    }
    delay(3000);
  }
}
boolean getUID()
{
  if (! mfrc522.PICC_IsNewCardPresent()) {
    //Serial.println("card Not found");
    return false;
  }

  if (! mfrc522.PICC_ReadCardSerial()) {
    //Serial.println("Not able to read the card");
    return false;
  }
  UIDCard = "";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    UIDCard.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    UIDCard.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  UIDCard.toUpperCase();
  UIDCard = UIDCard.substring(1);

  mfrc522.PICC_HaltA();
  return true;
}
 
3. In the arduino software goto Tool --> then select your board and COM port after that Upload the code.
4. After the code is successfully uploaded then we need to open the serial monitor which is on the top right corner. Its look like search button.
5. Now, we have to put master card on the RFID sensor to get the ID which we can use it in second code.

 Arduino RFID door lock code. 
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>

#define RST_PIN 9
#define SS_PIN  10

MFRC522 mfrc522(SS_PIN, RST_PIN);
String MasterTag = ""; // Enter you tag UID which we get it from first code. 

String UIDCard = "";

LiquidCrystal_I2C lcd(0x3F, 16, 2);

Servo servo;

#define BlueLED  2
#define GreenLED 3
#define RedLED 4

#define Buzzer 5

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  SPI.begin();
  mfrc522.PCD_Init();

  lcd.init();
  lcd.backlight();
  lcd.clear();

  servo.attach(6);
  servo.write(10);

  pinMode(GreenLED, OUTPUT);
  pinMode(BlueLED, OUTPUT);
  pinMode(RedLED, OUTPUT);

  pinMode(Buzzer, OUTPUT);

  digitalWrite(BlueLED, HIGH);

  lcd.clear();
  lcd.print(" Access Control ");
  lcd.setCursor(0, 1);
  lcd.print("Scan Your Card>>");
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(BlueLED, HIGH);
  digitalWrite(RedLED, LOW);
  digitalWrite(GreenLED, LOW);
  noTone(Buzzer);
  servo.write(10);
  //Wait until new tag is available
  while (getUID())
  {
    Serial.print("UID: ");
    Serial.println(UIDCard);
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("Permission");
    lcd.setCursor(0, 1);

    if (UIDCard == MasterTag)
    {
      lcd.print(" Access Granted!");
      digitalWrite(GreenLED, HIGH);
      digitalWrite(BlueLED, LOW);
      digitalWrite(RedLED, LOW);
      servo.write(100);
      delay(50);
      for (int i = 0; i < 2; i++) {
        tone(Buzzer, 2000);
        delay(250);
        noTone(Buzzer);
        delay(250);
      }
    }
    else
    {
      lcd.print(" Access Denied!");
      digitalWrite(BlueLED, LOW);
      digitalWrite(GreenLED, LOW);
      tone(Buzzer, 2000);
      servo.write(10);
      for(int i = 0; i < 10;i++){
        digitalWrite(RedLED, HIGH);
        delay(250);
        digitalWrite(RedLED, LOW);
        delay(250);
      }
      noTone(Buzzer);
    }

    delay(2000);

    lcd.clear();
    lcd.print(" Access Control ");
    lcd.setCursor(0, 1);
    lcd.print("Scan Your Card>>");
  }
}
boolean getUID()
{
  if (! mfrc522.PICC_IsNewCardPresent()) {
    //Serial.println("card Not found");
    return false;
  }

  if (! mfrc522.PICC_ReadCardSerial()) {
    //Serial.println("Not able to read the card");
    return false;
  }
  UIDCard = "";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    UIDCard.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    UIDCard.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  UIDCard.toUpperCase();
  UIDCard = UIDCard.substring(1);

  mfrc522.PICC_HaltA();
  return true;
}

6. On this code we need to enter the ID which we get it from first code.
7. After that upload the code And play with it.

Let me know in the comment section, What next project do you want to see.

Watch This Tutorial: 



Feel free to comment down if you have any problems.

Post a Comment

0Comments

Post a Comment (0)