#include <Wire.h>
#include <Keypad.h>
#define Password_Length 9
int ledPin = 13; // Set the pin for the LED (you can change this to any available digital pin)
char Data[Password_Length];
char Master[Password_Length] = "12345678";
byte data_count = 0;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(ledPin, OUTPUT); // Set the LED pin as output
}
void loop() {
Serial.println("Enter Password:");
customKey = customKeypad.getKey();
if (customKey) {
Data[data_count] = customKey;
Serial.print(Data[data_count]);
data_count++;
}
if (data_count == Password_Length-1 ) {
Serial.println(); // Print a new line after the password entry
if (!strcmp(Data, Master)) {
Serial.println("Correct");
digitalWrite(ledPin, HIGH); // Turn the LED on
delay(5000); // Keep the LED on for 5 seconds
digitalWrite(ledPin, LOW); // Turn the LED off
} else {
Serial.println("Incorrect");
delay(1000); // Wait for 1 second before clearing the data
}
clearData();
}
}
void clearData() {
while (data_count != 0) {
Data[data_count--] = 0;
}
}