#include <Arduino.h>
#include <Keypad.h>
const int ledPin = 4; // Built-in LED on many ESP32 boards, change if using an external LED
const String correctPassword = "1234"; // Set your desired password here
// Keypad configuration
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] = {5, 18, 19, 21}; // Connect to row pins
byte colPins[COLS] = {22, 23, 32, 33 }; // Connect to column pins
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String inputPassword = "";
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // Ensure LED is off initially
}
void loop() {
char key = keypad.getKey();
if (key) {
if (key == '#') { // Assuming '#' is used to submit the password
if (inputPassword == correctPassword) {
Serial.println("Password correct! Turning on the LED.");
digitalWrite(ledPin, HIGH); // Turn on the LED
delay(5000); // Keep the LED on for 5 seconds
digitalWrite(ledPin, LOW); // Turn off the LED
} else {
Serial.println("Incorrect password. Try again.");
}
inputPassword = ""; // Clear the input after checking
} else if (key == '*') { // Assuming '*' is used to clear the input
inputPassword = "";
Serial.println("Input cleared.");
} else {
inputPassword += key; // Append the key to the input password
Serial.print("Current input: ");
Serial.println(inputPassword);
}
}
}