// #include <Wire.h>
// #include <LiquidCrystal.h>
// #include <Keypad.h>
// #include <Servo.h>
// // Hitesh Patil
// // Define the LCD
// // LCD GP no. connections
// LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
// // Keypad Connections
// Servo Servo1;
// 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 = "AA2";
// void setup() {
// Servo1.attach(27);
// lcd.begin(20, 4); // initialize the LCD
// lcd.setCursor(2, 1);
// // 12345678901234567890
// lcd.print("smart DOOR LOCK");
// lcd.setCursor(1, 3);
// lcd.print("password Enter here");
// }
// void loop() {
// char enteredPassword[6];
// int passwordIndex = 0;
// // Get the password from the keypad
// while (passwordIndex < 5) {
// char key = keypad.getKey();
// if (key) {
// enteredPassword[passwordIndex++] = key;
// lcd.clear();
// lcd.setCursor(0, 1);
// lcd.print("Password : ");
// lcd.setCursor(11, 1);
// lcd.print(enteredPassword);
// delay(500); // Wait for 500 milliseconds to avoid rapid key presses
// // lcd.clear();
// }
// }
// // Null-terminate the entered password
// enteredPassword[5] = '\0';
// // enteredPassword.clear();
// lcd.clear();
// // Check the entered password
// if (strcmp(enteredPassword, correctPassword) == 0) {
// lcd.setCursor(3, 1);
// lcd.print("SUCCESSFULLY");
// lcd.setCursor(4, 2);
// lcd.print("DOOR OPEN");
// for (int i = 0; i < 10; i++) {
// Servo1.write(i);
// delay(50);
// }
// delay(2000); // Wait for 5 seconds
// lcd.clear();
// for (int i = 0; i < 90; i++) {
// Servo1.write(i);
// delay(100);
// }
// for (int i = 0; i < 5; i++) {
// enteredPassword[i] = '\0';
// }
// lcd.print("Enter your password");
// } else {
// lcd.print("Incorrect password");
// delay(2000); // Wait for 2 seconds
// }
// for (int i = 0; i < 5; i++) {
// enteredPassword[i] = '\0';
// }
// lcd.clear();
// lcd.print("Enter your password");
// }
#include <Wire.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Servo.h>
// Hitesh Patil
// Define the LCD
// LCD GP no. connections
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
// Keypad Connections
Servo Servo1;
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 = "AA2";
void setup() {
Servo1.attach(27);
lcd.begin(20, 4); // Initialize the LCD
lcd.setCursor(2, 1);
lcd.print("smart DOOR LOCK");
lcd.setCursor(1, 3);
lcd.print("password Enter here");
}
void loop() {
char enteredPassword[6];
int passwordIndex = 0;
// Get the password from the keypad
while (passwordIndex < 5) {
char key = keypad.getKey();
if (key) {
enteredPassword[passwordIndex++] = key;
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Password : ");
// Display asterisks instead of the actual password
lcd.setCursor(11, 1);
for (int i = 0; i < passwordIndex; i++) {
lcd.print('*'); // Print an asterisk for each character entered
}
delay(500); // Wait for 500 milliseconds to avoid rapid key presses
}
}
// Null-terminate the entered password
enteredPassword[5] = '\0';
lcd.clear();
// Check the entered password
if (strcmp(enteredPassword, correctPassword) == 0) {
lcd.setCursor(3, 1);
lcd.print("SUCCESSFULLY");
lcd.setCursor(4, 2);
lcd.print("DOOR OPEN");
for (int i = 0; i < 10; i++) {
Servo1.write(i);
delay(50);
}
delay(2000); // Wait for 2 seconds
lcd.clear();
for (int i = 0; i < 90; i++) {
Servo1.write(i);
delay(100);
}
// Clear entered password
for (int i = 0; i < 5; i++) {
enteredPassword[i] = '\0';
}
lcd.print("Enter your password");
} else {
lcd.print("Incorrect password");
delay(2000); // Wait for 2 seconds
}
// Clear entered password
for (int i = 0; i < 5; i++) {
enteredPassword[i] = '\0';
}
lcd.clear();
lcd.print("Enter your password");
}