Arduino UNO-Based Door Lock System with Keypad and LCD Display
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is a door lock system that uses a 4x4 keypad, an LCD display with I2C interface, 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 to unlock the door.
Component List
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
LCD I2C Display
- Description: A 16x2 character LCD display with I2C interface.
- Pins: GND, VCC, SDA, SCL
Relay Module 1 Channel
- Description: A single-channel relay module used to control high voltage devices.
- Pins: S, 5V, GND, NC, COM, NO
4X4 Membrane Matrix Keypad
- Description: A 4x4 matrix keypad used for user input.
- Pins: R1, R2, R3, R4, C1, C2, C3, C4
12V Solenoid Lock
- Description: A solenoid lock that operates on 12V.
- Pins: VCC, GND
9V Battery
- Description: A 9V battery used to power the solenoid lock.
- Pins: -, +
Wiring Details
Arduino UNO
- 5V connected to 5V of Relay Module and VCC of LCD I2C Display
- GND connected to GND of Relay Module and GND of LCD I2C Display
- A4 connected to SDA of LCD I2C Display
- A5 connected to SCL of LCD I2C Display
- D10 connected to S of Relay Module
- D9 connected to R1 of 4X4 Membrane Matrix Keypad
- D8 connected to R2 of 4X4 Membrane Matrix Keypad
- D7 connected to R3 of 4X4 Membrane Matrix Keypad
- D6 connected to R4 of 4X4 Membrane Matrix Keypad
- D5 connected to C1 of 4X4 Membrane Matrix Keypad
- D4 connected to C2 of 4X4 Membrane Matrix Keypad
- D3 connected to C3 of 4X4 Membrane Matrix Keypad
- D2 connected to C4 of 4X4 Membrane Matrix Keypad
LCD I2C Display
- VCC connected to 5V of Arduino UNO
- GND connected to GND of Arduino UNO
- SDA connected to A4 of Arduino UNO
- SCL connected to A5 of Arduino UNO
Relay Module 1 Channel
- 5V connected to 5V of Arduino UNO
- GND connected to GND of Arduino UNO
- S connected to D10 of Arduino UNO
- COM connected to + of 9V Battery
- NO connected to VCC of 12V Solenoid Lock
4X4 Membrane Matrix Keypad
- R1 connected to D9 of Arduino UNO
- R2 connected to D8 of Arduino UNO
- R3 connected to D7 of Arduino UNO
- R4 connected to D6 of Arduino UNO
- C1 connected to D5 of Arduino UNO
- C2 connected to D4 of Arduino UNO
- C3 connected to D3 of Arduino UNO
- C4 connected to D2 of Arduino UNO
12V Solenoid Lock
- VCC connected to NO of Relay Module
- GND connected to - of 9V Battery
9V Battery
- + connected to COM of Relay Module
- - connected to GND of 12V Solenoid Lock
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 entered password matches the predefined password, the relay is activated to unlock the door. If the password is incorrect, an "Access Denied" message is displayed. The system also includes a timeout feature to clear the input after a period of inactivity.