#include <Arduino.h>
#include <Keypad.h>
// Define keypad layout
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
byte rowPins[ROWS] = { A5, A4 , A3, A2 }; // Example row pins
byte colPins[COLS] = { A1, A0, D7, D8 }; // Example column pins
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// LED pin
const int ledPin = D4; // GPIO 4
// Password to operate the LED
const char* password = "22138059"; // Replace with your registration number
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
}
void loop() {
static char inputpad[20]; // Buffer to store entered password
static int inputpadIndex = 0;
char key = keypad.getKey();
if (key != NO_KEY) {
Serial.println(key);
inputpad[inputpadIndex++] = key;
inputpad[inputpadIndex] = '\0'; // Null-terminate the string
// Check if the entered password matches
if (strcmp(inputpad, password) == 0) {
digitalWrite(ledPin, HIGH); // Turn on LED
delay(1000); // Delay for 1 second
digitalWrite(ledPin, LOW); // Turn off LED
inputpadIndex = 0; // Reset buffer
}
// Clear buffer if wrong password
else if (inputpadIndex >= strlen(password)) {
inputpadIndex = 0; // Reset buffer
}
}
}