#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const byte num_row=4;
const byte num_col=4;
String text="";
int count=0;
int a=0;
int r=13;
int g=3;
char key[num_row][num_col]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','c'},
{'*','0','E','D'}
};
byte rowpin[num_row]={12,11,10,9};
byte colpin[num_col]={7,6,5,4};
Keypad keypad=Keypad(makeKeymap(key),rowpin,colpin,num_row,num_col);
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
lcd.backlight();
pinMode(3, OUTPUT);
pinMode(13, OUTPUT);
lcd.setCursor(0,0);
lcd.print("WELCOME");
lcd.setCursor(0,1);
lcd.print("SECURITY SYSTEM");
delay(3000);
lcd.clear();
}
void loop() {
// put your main code here, to run repeatedly:
char key=keypad.getKey();
if(key)
{
text+=key;
count++;
if(count>5)
{
lcd.clear();
lcd.print("invaid lenght");
count=0;
}
lcd.print("*");
if(key=='A')
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter password");
lcd.setCursor(3,1);
text="";
}
else if(key=='*')
{
lcd.clear();
a=0;
count=0;
digitalWrite(r, LOW);
digitalWrite(g, LOW);
}
if(key=='E')
{
lcd.setCursor(3,1);
lcd.clear();
if(text=="9876E")
{
lcd.print("vaild password");
digitalWrite(g, HIGH);
digitalWrite(r,LOW);
delay(3000);
digitalWrite(g,LOW);
count=0;
lcd.clear();
}
else
{
lcd.print("invalid pass...");
digitalWrite(r,HIGH);
digitalWrite(g,LOW);
delay(2000);
digitalWrite(r, LOW);
lcd.clear();
a++;
}
if(a==3)
{
digitalWrite(r, HIGH);
delay(2000);
digitalWrite(g, LOW);
a=0;
}
}
}
}