Intermediatearduino

Smart Door Lock with Keypad and RFID

Dual-access smart door lock supporting both keypad PIN codes and RFID card authentication.

3-4 hours
$20-35
Marcus Johnson
Smart Door Lock with Keypad and RFID

Parts List

  • Arduino Uno
  • 4x4 Keypad Module
  • MFRC522 RFID Module
  • Servo Motor
  • LCD 16x2
  • Buzzer

Step-by-Step Instructions

1

Wire Keypad

Connect the 4x4 matrix keypad to Arduino digital pins 2 through 9, with the four rows on pins 2-5 and four columns on pins 6-9. Use the Keypad library to define the button layout map and configure the library to scan the matrix efficiently. Test each button by printing the detected key to the Serial Monitor before proceeding to the RFID module wiring.

2

Wire RFID Module

Connect the MFRC522 RFID module to the Arduino via SPI: SDA to pin 10, SCK to pin 13, MOSI to pin 11, MISO to pin 12, and RST to pin 9. Power the module from the 3.3V pin and ground, ensuring no connection to 5V to prevent damage. Mount the RFID reader near the door frame at a comfortable scanning height and route the wiring neatly to avoid interference with the door mechanism.

3

Mount Servo Lock

Attach the servo motor to the door frame or deadbolt mechanism using a custom 3D-printed bracket or strong double-sided mounting tape. Connect the servo horn to the deadbolt so that rotating to 0 degrees locks the door and rotating to 90 degrees unlocks it. Wire the servo signal pin to Arduino pin 3, VCC to 5V, and GND to ground, and test the full range of motion before final installation.

4

Write Dual Auth Code

Write an Arduino sketch that supports two authentication modes: keypad PIN entry and RFID card scanning. Define a default PIN code and store authorized RFID UIDs in an array, comparing each input against the whitelist. Display the current mode on the LCD screen and provide a mode-switch button that toggles between PIN and RFID input, with buzzer feedback for successful and failed authentication attempts.

#include <MFRC522.h>
#include <Keypad.h>
#include <LiquidCrystal.h>

MFRC522 rfid(10, 9);
LiquidCrystal lcd(A0, A1, 5, 4, 3, 2);
bool rfidMode = true;
char pin[] = "1234";
char input[5];
int pinIdx = 0;

void setup() {
  SPI.begin();
  rfid.PCD_Init();
  lcd.begin(16, 2);
  pinMode(7, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(7), toggleMode, FALLING);
}

void loop() {
  if (rfidMode) {
    if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) {
      // Check authorized UIDs
      lcd.print("RFID Scanned");
    }
  } else {
    char key = keypad.getKey();
    if (key) {
      input[pinIdx++] = key;
      lcd.print('*');
      if (pinIdx == 4) {
        input[4] = '\0';
        if (strcmp(input, pin) == 0) unlock();
        pinIdx = 0;
      }
    }
  }
}