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

ESP32-Based Smart Door Lock with RFID, Keypad, and LCD Display

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Door Lock with RFID, Keypad, and LCD Display

Smart Door Lock Circuit Documentation

Summary

This document provides a detailed overview of a smart door lock system. The system integrates an RFID reader, a 4x4 membrane keypad, an ESP32 microcontroller, an I2C LCD screen, a relay module, and a 12V solenoid lock. The ESP32 microcontroller serves as the central control unit, interfacing with the other components to manage access control via RFID cards and keypad input.

Component List

RFID-RC522

4X4 Membrane Matrix Keypad

ESP32 Wroom Dev Kit

I2C LCD 16x2 Screen

Relay Module 5V-30V

12V Solenoid Lock

Wiring Details

RFID-RC522

4X4 Membrane Matrix Keypad

ESP32 Wroom Dev Kit

I2C LCD 16x2 Screen

Relay Module 5V-30V

12V Solenoid Lock

Code Documentation

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <MFRC522.h>
#include <Keypad.h>

// LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 2);

// RFID setup
#define SDA_PIN 2
#define SCK_PIN 18
#define MOSI_PIN 23
#define MISO_PIN 19
#define RST_PIN 4
MFRC522 rfid(SDA_PIN, RST_PIN);

// Keypad setup
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {13, 12, 13, 27}; // R1-R4
byte colPins[COLS] = {26, 25, 25, 33}; // C1-C4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

// Relay pin setup
#define RELAY_PIN 35
bool isLocked = true; // Initial state

// Predefined access key
String validRFID = "DEADBEEF"; // Replace with your card's UID
String validPasscode = "1234";

// Variables
String enteredCode = "";

void setup() {
  // Initialize Serial
  Serial.begin(115200);

  // Initialize LCD
  lcd.init();
  lcd.backlight();
  lcd.print("Smart Door Lock");
  delay(2000);
  lcd.clear();

  // Initialize RFID
  SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN);
  rfid.PCD_Init();

  // Initialize relay
  pinMode(RELAY_PIN, OUTPUT);
  lockDoor();

  // Ready message
  lcd.setCursor(0, 0);
  lcd.print("Place RFID or");
  lcd.setCursor(0, 1);
  lcd.print("Enter Passcode");
}

void loop() {
  // Check for RFID card
  if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) {
    String uid = getUID();
    if (uid == validRFID) {
      unlockDoor("RFID");
    } else {
      lcd.clear();
      lcd.print("Access Denied");
      delay(2000);
      lcd.clear();
    }
    rfid.PICC_HaltA();
  }

  // Check for keypad input
  char key = keypad.getKey();
  if (key) {
    lcd.setCursor(0, 1);
    if (key == '#') {
      if (enteredCode == validPasscode) {
        unlockDoor("Keypad");
      } else {
        lcd.clear();
        lcd.print("Wrong Passcode");
        delay(2000);
      }
      enteredCode = "";
      lcd.clear();
    } else if (key == '*') {
      enteredCode = ""; // Clear input
      lcd.clear();
    } else {
      enteredCode += key;
      lcd.print('*');
    }
  }
}

String getUID() {
  String uid = "";
  for (byte i = 0; i < rfid.uid