#include <Wire.h>// library to invoke I2C protocol
#include <LiquidCrystal_I2C.h>//library to interface the I2C breakout board with the LCd display
#include <Keypad.h>// the matrix keypad library
#include <Servo.h>
Servo myServo;
char sandi[3] = {'9','4','5'};
int a = 0;
char customKey[3];
const byte ROWS = 4;// number of rows on the keypad
const byte COLS = 4;// number of columns on the keypad
char hexaKeys[ROWS][COLS] = { // mapping the keys to characters
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //Arduino pins connected to row pins of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; // Arduino pins connected to column pins of the keypad
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);//associating the arduino pins that are connected to
//the keypad to the various characters
LiquidCrystal_I2C lcd(0x27, 16, 2); // associating the LCD with the I2C Serial bus
void setup()
{
myServo.attach(11);
lcd.backlight();//setting up the LCD's backlight
lcd.init(); // initialise the LCD
Serial.begin(9600);//initialise Serial communication
}
void loop(){
customKey[a] = customKeypad.getKey();//awaiting key press
if (customKey[a])//checking whether a key is press
{
lcd.setCursor(a, 0); //setting printing position on the LCD
lcd.print(customKey[a]);//print the key pressed on the LCD
Serial.println(customKey[a]);//print the pressed key on the Serial monitor
if(customKey[0]==sandi[0]&&customKey[1]==sandi[1]&&customKey[2]==sandi[2]){
myServo.write(180);
delay(1000);
lcd.clear();
}
a++;
if(a>=3){
delay(1000);
lcd.clear();//clears the LCD
a = 0;
}
myServo.write(90);
}
}