Simple And Easy RFID Door Lock

🔒  RFID Door Lock   ðŸ”’



Overview

RFID (Radio Frequency Identification) door lock system allows you to unlock a door using an RFID card or key fob. The system reads the unique ID from the RFID tag and compares it against a predefined list of authorized IDs. If a match is found, it activates an electronic lock (like a solenoid lock or relay).


What You Need..

  1. Arduino Board (like Arduino Uno or Nano)
  2. RFID Reader (like MFRC522)
  3. RFID Cards or Key Fobs (small tags that unlock the door)
  4. Servo Motor (to unlock the door)
  5. Breadboard and Jumper Wires
  6. Power Supply (to power the Arduino and servo)
  7. LED (optional, for a light indicator)
  8. Buzzer (optional, for sound alerts)


Basic Idea

You will use the RFID reader to scan a card. If the card is on the list of approved cards, it will unlock the door using a servo motor.


RFID Door Lock System Pin Connections

Component Pin Name Arduino Pin
RFID Reader (MFRC522) SDA (SS) 10
RFID Reader (MFRC522) SCK 13
RFID Reader (MFRC522) MOSI 11
RFID Reader (MFRC522) MISO 12
RFID Reader (MFRC522) RST 9
RFID Reader (MFRC522) VCC 3.3V
RFID Reader (MFRC522) GND GND
Servo Motor Signal Pin 8
Servo Motor VCC 5V
Servo Motor GND GND


Circuit Diagram



Step-by-Step Instructions:

1. Install Required Libraries

You need the MFRC522 library to interact with the RFID reader. Install it via the Arduino IDE Library Manager:
  • Open Arduino IDE.
  • Go to Sketch > Include Library > Manage Libraries.
  • Search for MFRC522 and install it.

Arduino Code


#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>

#define SS_PIN 10
#define RST_PIN 9
#define SERVO_PIN 8

MFRC522 rfid(SS_PIN, RST_PIN);
Servo myServo;

// Define authorized RFID card UID
byte authorizedUID[] = {0xDE, 0xAD, 0xBE, 0xEF}; // Example UID (Replace with your own UID)

void setup() {
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();
  myServo.attach(SERVO_PIN);
  myServo.write(0); // Start with the lock closed
  Serial.println("Place your card near the reader...");
}

void loop() {
  // Check for new RFID cards
  if (!rfid.PICC_IsNewCardPresent()) {
    return;
  }

  // Select one of the cards
  if (!rfid.PICC_ReadCardSerial()) {
    return;
  }

  // Print UID to Serial Monitor
  Serial.print("UID tag : ");
  for (byte i = 0; i < rfid.uid.size; i++) {
    Serial.print(rfid.uid.uidByte[i], HEX);
    Serial.print(" ");
  }
  Serial.println();

  // Check if the scanned UID matches the authorized UID
  if (compareUID(rfid.uid.uidByte, authorizedUID, rfid.uid.size)) {
    Serial.println("Access Granted!");
    myServo.write(90); // Unlock the door
    delay(3000); // Keep it unlocked for 3 seconds
    myServo.write(0); // Lock the door again
  } else {
    Serial.println("Access Denied!");
  }

  rfid.PICC_HaltA(); // Stop reading
}

bool compareUID(byte *uid, byte *authorizedUID, byte uidSize) {
  for (byte i = 0; i < uidSize; i++) {
    if (uid[i] != authorizedUID[i]) {
      return false; // UID does not match
    }
  }
  return true; // UID matches
}

3. Upload the Code

  • Connect your Arduino board to your computer.
  • Select the appropriate board and port in the Arduino IDE.
  • Click on the upload button to upload the code to the Arduino.


4. Testing the System

  1. Power On: Connect your Arduino to a power supply.
  2. Place the RFID Card: Bring your RFID card or key fob close to the RFID reader.
  3. Observe the Output: Check the Serial Monitor for messages about access granted or denied. The servo should turn to unlock the door if the card is authorized.


Explanation of the Code

  • Libraries: The code includes necessary libraries for SPI communication and the MFRC522 RFID module.
  • Initialization: The RFID reader is initialized, and the servo is attached to a specific pin.
  • Loop Function: Continuously checks for new RFID cards and reads their UID.
  • UID Comparison: The scanned UID is compared against a predefined authorized UID array.
  • Servo Control: If access is granted, the servo unlocks the door for a few seconds before locking again.


Additional Features

You can expand the system with additional features, such as:

  1. Multiple Authorized Users: Use an array to store multiple authorized UIDs.
  2. Buzzer Feedback: Add a buzzer that sounds when access is granted or denied.
  3. Logging: Keep track of access attempts by logging UIDs to an SD card.
  4. Mobile App Control: Use Bluetooth or Wi-Fi to control the lock remotely.


Conclusion

This RFID Door Lock System is a great way to learn about Arduino, RFID technology, and basic electronics. It can be further customized and enhanced based on your needs and preferences, making it a versatile project!

Post a Comment

0 Comments