Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO-Based RFID and Keypad Door Lock System with Servo Motor

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based RFID and Keypad Door Lock System with Servo Motor

Door Locking System using RFID, Keypad, Servo Motor, and Arduino UNO

Summary

This project is a door locking system that utilizes an Arduino UNO microcontroller, an RFID reader (RFID-RC522), a 4x4 membrane matrix keypad, and a 9G servo motor. The system unlocks a door when either the correct RFID tag is scanned or the correct password is entered on the keypad. The servo motor rotates to unlock the door upon successful authentication.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. RFID-RC522

    • Description: An RFID reader module that operates at 13.56 MHz.
    • Pins: VCC (3.3V), RST, GND, IRQ, MISO, MOSI, SCK, SDA
  3. 4X4 Membrane Matrix Keypad

    • Description: A 4x4 matrix keypad used for user input.
    • Pins: R1, R2, R3, R4, C1, C2, C3, C4
  4. Servo Motor 9G

    • Description: A small servo motor used to control the locking mechanism.
    • Pins: VCC 5V, PMW, GND

Wiring Details

Arduino UNO

RFID-RC522

4X4 Membrane Matrix Keypad

Servo Motor 9G

Code Documentation

/*
 * Project: Door Locking System using RFID, Keypad, Servo Motor, and Arduino UNO
 * Description: This project unlocks a door using either an RFID tag or a keypad.
 * If the correct password is entered on the keypad or the correct RFID tag is
 * scanned, the servo motor will rotate to unlock the door.
 */

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

// Pin definitions
#define RST_PIN 9
#define SS_PIN 10
#define SERVO_PIN 3

// RFID setup
MFRC522 rfid(SS_PIN, RST_PIN);

// Servo setup
Servo myServo;

// Keypad setup
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; // Connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8, 9}; // Connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

// Password and RFID tag
String correctPassword = "1234";
String inputPassword;
byte correctTag[4] = {0xDE, 0xAD, 0xBE, 0xEF};

void setup() {
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();
  myServo.attach(SERVO_PIN);
  myServo.write(0); // Lock position
  Serial.println("System Ready");
}

void loop() {
  // Check RFID
  if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) {
    if (checkRFID()) {
      unlockDoor();
    }
    rfid.PICC_HaltA();
  }

  // Check Keypad
  char key = keypad.getKey();
  if (key) {
    if (key == '#') {
      if (inputPassword == correctPassword) {
        unlockDoor();
      }
      inputPassword = "";
    } else if (key == '*') {
      inputPassword = "";
    } else {
      inputPassword += key;
    }
  }
}

bool checkRFID() {
  for (byte i = 0; i < 4; i++) {
    if (rfid.uid.uidByte[i] != correctTag[i]) {
      return false;
    }
  }
  return true;
}

void unlockDoor() {
  Serial.println("Door Unlocked");
  myServo.write(90); // Unlock position
  delay(5000); // Keep unlocked for 5 seconds
  myServo.write(0); // Lock position
  Serial.println("Door Locked");
}

This code initializes the RFID reader, servo motor, and keypad. It continuously checks for a valid RFID tag or the correct password entered on the keypad. If either is detected, the servo motor rotates to unlock the door for 5 seconds before returning to the locked position.