#include <Wire.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
// Aditya Vijay Patil
// Define the LCD
// LCD GP no. connections
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
// Keypad Connections
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'}
};
//connect to the row pinouts of the keypad
byte rowPins[ROWS] = {26, 22, 21, 20};
//connect to the column pinouts of the keypad
byte colPins[COLS] = {19, 18, 17, 16};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Define correct password
const char* correctPassword = "9421";
void setup() {
lcd.begin(20, 4); // initialize the LCD
lcd.setCursor(0, 0);
// 12345678901234567890
lcd.print("Keypad Door Lock");
lcd.setCursor(0, 1);
lcd.print("Enter Your Password");
lcd.setCursor(0, 2);
lcd.print("To Open Door");
lcd.setCursor(0, 3);
lcd.print("Password : ");
}
void loop() {
char enteredPassword[5];
int passwordIndex = 0;
// Get the password from the keypad
while (passwordIndex < 4) {
char key = keypad.getKey();
if (key) {
enteredPassword[passwordIndex++] = key;
lcd.clear();
lcd.print("Password : ");
lcd.setCursor(12, 3);
lcd.print(enteredPassword);
delay(500); // Wait for 500 milliseconds to avoid rapid key presses
// lcd.clear();
}
}
// Null-terminate the entered password
enteredPassword[4] = '\0';
lcd.clear();
// Check the entered password
if (strcmp(enteredPassword, correctPassword) == 0) {
lcd.print("Successfully");
lcd.setCursor(0, 1);
lcd.print("Door");
lcd.setCursor(0, 2);
lcd.print("Open");
delay(5000); // Wait for 5 seconds
lcd.clear();
lcd.print("Enter your password");
} else {
lcd.print("Incorrect password");
delay(2000); // Wait for 2 seconds
}
lcd.clear();
lcd.print("Enter your password");
}