#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//include keypad library//
#include <Keypad.h>
#include <Servo.h>
Servo myservo;
//define the constants for row and column sizes//
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys [ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
//Connect to Arduino
byte rowPins[ROWS] = {9,8,7,6};
byte colPins[COLS] = {5,4,3,2};
//Create keypad object
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins,colPins, ROWS, COLS);
//Create LCD Screen Object
LiquidCrystal_I2C lcd(0x27,20,4);
char password[5];
char initialpassword[5],newpassword[5];
int i = 0;
int pos = 0;
char S[5] = "1234";
int buzz = 0;
void setup() {
myservo.attach(14);
myservo.write(pos);
Serial.begin(9600);
pinMode(buzz, OUTPUT);
//Setup LCD with backlight and initialise
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Enter Password:");
}
void loop() {
char key =customKeypad.getKey();
if (key){
if(key!='#' && key!='D'){
//Serial.print('*)
lcd.setCursor(i,1);
lcd.print('*');
password[i]=key;
password[i+1] = NULL;
i++;
}
}
if(key=='#')
{
//Serial.println();
if(strcmp(password,S)==0)
{
//Serial.println("ACCESS GRANTED");
lcd.clear();
lcd.print("ACCESS GRANTED");
delay(3000);
lcd.clear();
lcd.print("WELCOME HOME!!");
servo_t;
clearerr;
}
else if(strcmp(password,S)!=0)
{
//Serial.println("ACCESS DENIED");
lcd.clear();
lcd.print("ACCESS DENIED");
delay(2000);
lcd.setCursor(0,0);
lcd.print("Enter Password");
clearerr;
}
i=0;
}
}
void servoOpen()
{
for(;pos<=180;pos+=10)
{
myservo.write(pos);
delay(40);
}
}
void ServoClose()
{
for(;pos>=0;pos-=10)
{
myservo.write(pos);
delay(40);
}
}
void clearData()
{
password[0]=NULL;
}