Document4
Document4
h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
Servo myServo;
// Create LCD object (Address 0x27, 16x2 LCD display)
// Timer for inactivity (e.g., 5 seconds of inactivity before closing the servo)
void setup() {
myServo.attach(9);
Serial.begin(9600);
// Initialize LCD
lcd.begin(16, 2); // Initialize the LCD
lcd.clear();
void loop() {
if (key) {
lastKeyPressTime = millis();
if (seqIndex == passwordLength) {
// Compare the entered sequence with the password
if (!servoOpen) {
servoOpen = true;
lcd.clear();
lcd.print("Access Granted");
} else {
lcd.clear();
lcd.print("Access Declined");
servoOpen = false;
lcd.clear();
lcd.print("Servo Closed");