#define servo_pin 23
#include<ESP32Servo.h>
Servo servo;
#include <Keypad.h>
#define ROW_NUM 4 // four rows
#define COLUMN_NUM 4 // four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte pin_rows[ROW_NUM] = {22, 21, 19, 18}; // GPIO19, GPIO18, GPIO5, GPIO17 connect to the row pins
byte pin_column[COLUMN_NUM] = {5, 17, 16, 4}; // GPIO16, GPIO4, GPIO0, GPIO2 connect to the column pins
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
String password="1234";
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
servo.attach(servo_pin);
servo.write(0);
}
void loop()
{
char key=keypad.getKey();
if (key!=NO_KEY)
{
Serial.print(key);
checkPassword(key);
}
delay(50);
}//end of loop
void open()
{
for(int i=0; i<=180; i=i+5)
{
servo.write(i);
delay(50);
}
}
void close()
{
for(int i=180; i>=0; i=i-5)
{
servo.write(i);
delay(50);
}
}
String entered_password="";
void checkPassword(char key)
{
if (key=='#')
{
if (entered_password==password)
{
Serial.println("Correct Password");
open();
delay(3000);
close();
}
else
{
Serial.println("Incorrect Password");
}
entered_password="";
}
else
{
entered_password +=key;
}
}