#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] = {9, 8, 7, 6}; // Connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; // Connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
const int ledPin = 13; // LED connected to digital pin 13
String inputPassword = "";
const String password = "8714";
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // Ensure LED is off initially
Serial.begin(9600);
}
void loop() {
char key = keypad.getKey();
if (key) {
Serial.println(key);
if (key == 'C') {
digitalWrite(ledPin, LOW); // Turn off LED
inputPassword = ""; // Reset input
} else if (key == '#') {
if (inputPassword == password) {
digitalWrite(ledPin, HIGH); // Turn on LED
}
inputPassword = ""; // Reset input
} else {
inputPassword += key; // Append key to input
}
}
}