Arduino with keypad and lcd (smart lock tutorial) (Code)

TUTORIAL


Arduino with keypad and lcd (smart lock tutorial) (Code)

#include [LiquidCrystal.h]
#include [Keypad.h]
char password[6] ="*6D#0A";
int keyposition = 0; //keypad position
const byte rows = 4; //number of the keypad's rows and columns
const byte columns = 4;
char keyMap [rows] [columns] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins [rows] = {1, 2, 3, 4}; //pins of the keypad
byte colPins [columns] = {5, 6, 7, 8};
Keypad kibrdkeys = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, columns);
const int rs = A0, en = A1, d4 = A2, d5 = A3, d6 = A4, d7 = A5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup(){
lcd.begin(16, 2);
}
void loop(){
char enteredKey = kibrdkeys.getKey();
lcd.setCursor(0, 0);
lcd.print("Welcome");
lcd.setCursor(0, 1);
lcd.print("Enter Password");
if(enteredKey == '1' ||
enteredKey == '2' ||
enteredKey == '3' ||
enteredKey == '4' ||
enteredKey == '5' ||
enteredKey == '7' ||
enteredKey =='8' ||
enteredKey== '9' ||
enteredKey== 'C' ||
enteredKey =='B' )
{
keyposition=0;
lcd.clear();
lcd.print("Invalid bro!!!");
delay(1000);
lcd.clear();
}
if(enteredKey == password [keyposition]){
keyposition++;
}
if(keyposition == 6){
lcd.clear();
lcd.print("Accepted");
delay(10000);
lcd.clear();
keyposition=0;
}
}
For a tutorial about this project please check the link.
NOTE: Please change [] this sign to <> in first two lines.

Comments