#include <Keypad.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] = {18, 5, 17, 16}; // Connect to row pinouts of keypad
byte colPins[COLS] = {4, 0, 2, 15}; // Connect to column pinouts of keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String password = "1234"; // Set your password here
String enteredPassword = "";
const int ledPin = 19; // LED indicator
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.print(key);
if (key == '#') { // Check if entered password is correct
if (enteredPassword == password) {
Serial.println("\nAccess Granted!");
digitalWrite(ledPin, HIGH);
} else {
Serial.println("\nAccess Denied!");
digitalWrite(ledPin, LOW);
}
enteredPassword = ""; // Reset password entry
} else if (key == '*') {
enteredPassword = ""; // Reset password
Serial.println("969140");
} else {
enteredPassword += key; // Append key to entered password
}
}
}
// Define the pin connected to the LED
const int ledPin = 13;
void setup() {
// Initialize the digital pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Turn the LED on
digitalWrite(ledPin, HIGH);
// Wait for 1 second
delay(1000);
// Turn the LED off
digitalWrite(ledPin, LOW);
// Wait for 1 second
delay(1000);
}