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

Arduino UNO-Based Door Lock System with Keypad and LCD Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Door Lock System with Keypad and LCD Display

Circuit Documentation

Summary

This circuit is a door lock system that uses a 4x4 membrane matrix keypad, an LCD I2C display, and a relay module to control a 12V solenoid lock. The system is controlled by an Arduino UNO microcontroller. The user inputs a password via the keypad, which is displayed on the LCD. If the entered password matches the predefined password, the relay is activated, unlocking the solenoid lock.

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. LCD I2C Display

    • Description: A 16x2 character LCD display with I2C interface.
    • Pins: GND, VCC, SDA, SCL
  3. Relay Module 1 Channel

    • Description: A single-channel relay module used to control high voltage devices.
    • Pins: S, 5V, GND, NC, COM, NO
  4. 4X4 Membrane Matrix Keypad

    • Description: A 4x4 matrix keypad used for user input.
    • Pins: R1, R2, R3, R4, C1, C2, C3, C4
  5. 12V Solenoid Lock

    • Description: An electronic lock that operates on 12V.
    • Pins: VCC, GND
  6. 9V Battery

    • Description: A 9V battery used to power the solenoid lock.
    • Pins: -, +

Wiring Details

Arduino UNO

LCD I2C Display

Relay Module 1 Channel

4X4 Membrane Matrix Keypad

12V Solenoid Lock

9V Battery

Code Documentation

/*
 * Door Lock System using 4x4 Keypad, LCD, and Relay
 * This code reads input from a 4x4 keypad, displays it on an LCD using I2C,
 * and checks if the entered code matches a predefined password to
 * unlock the door by activating a relay. Feedback is provided on incorrect
 * entry, and blocking delays are prevented.
 * Password: 1234
 */

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

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] = {9, 8, 7, 6}; // Connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; // Connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16 chars and 2 line display

const int relayPin = 10; // Pin connected to the relay
String password = "1234";
String input = "";
unsigned long lastInteraction = 0;
const unsigned long timeout = 3000; // 3 seconds timeout for feedback

void setup() {
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW); // Ensure relay is off initially
  lcd.begin(16,2);
  lcd.backlight();
  lcd.print("Enter Password:");
}

void loop() {
  char key = keypad.getKey();
  if (key) {
    lastInteraction = millis();
    if (key == '#') {
      if (input == password) {
        lcd.clear();
        lcd.print("Access Granted");
        digitalWrite(relayPin, HIGH); // Activate relay
        delay(5000); // Keep relay on for 5 seconds
        digitalWrite(relayPin, LOW); // Deactivate relay
      } else {
        lcd.clear();
        lcd.print("Access Denied");
      }
      input = "";
    } else if (key == '*') {
      input = "";
      lcd.clear();
      lcd.print("Enter Password:");
    } else {
      input += key;
      lcd.setCursor(0, 1);
      lcd.print(input);
    }
  }
  if (millis() - lastInteraction > timeout && input != "") {
    lcd.clear();
    lcd.print("Enter Password:");
    input = "";
  }
}

This code initializes the keypad and LCD, sets up the relay pin, and continuously checks for key presses. When a key is pressed, it updates the input string and displays it on the LCD. If the '#' key is pressed, it checks if the input matches the predefined password. If it does, it activates the relay to unlock the door. If the '*' key is pressed, it clears the input. The code also includes a timeout feature to clear the input if no key is pressed for 3 seconds.