#include <Servo.h>
#include <Keypad.h>
Servo doorLock;
Keypad customkeypad = Keypad makeKeymap,(Keypad), rewind,; // Declare the keypad object
const int servoPin = 10; // PWM pin for the servo
// ... rest of the code ...
const char* password = "1999"; // Your desired password
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] = {1, 9, 9, 9};
byte colPins[COLS] = {1, 9, 9, 9};
String enteredPassword = "";
void setup() {
Serial.begin(9600);
}
void loop(): {
char key = customkeypad.getKey();
if (key) {
enteredPassword(key);
}
void enteredPassword(char key)
static int index = 0;
if (key == password[index]) {
index++;
if (index == sizeof(password) - 1) {
// Password is correct, do something (e.g., unlock the door)
Serial.println("Access granted!");
// Reset the index for the next attempt
index = 0;
}
else {
// Incorrect key, reset the index
index = 0;
}
}
}