- Arduino uno
- LCD display
- Keypad
- LED bulb
- 10k potentiometer
- Breadboard
Connections:-
Display pins
Display pins
Vss = Arduino GND
VDD = Arduino 5V
V0 = Potentiometer center pin
RS = Analog pin 5
RW = Arduino GND
E = Analog pin 4
D4 = Arduino Analog pin 0
D5 = Arduino analog pin 1
D6 = Arduino analog pin 2
D7 = Arduino analog pin 3
D7 = Arduino analog pin 3
A = Arduino 5V/3.5V
K = Arduino GND
Keypad pins
keypad left pin to right=Arduino digital pin 0 to 7
LED pins
LED (+) = Arduino digital pin 13
LED (-) = Arduino GND
Libraries:-
Code:-
#include <LiquidCrystal.h> //include LCD library
#include <Keypad.h> //include keypad library
//define the LED pins
#define LED 13
char* password ="1234"; //create a password
int pozisyon = 0;
const byte rows = 4; //number of the keypad's rows
const byte cols = 4;//number of the keypad's columns
char keyMap [rows] [cols] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins [rows] = {0, 1, 2, 3}; //pins of the keypad
byte colPins [cols] = {4, 5, 6, 7};
Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);
LiquidCrystal lcd (A5, A4, A0, A1, A2, A3); // pins of the LCD.
void setup(){
lcd.begin(16, 2);
pinMode(LED, OUTPUT);
setLocked (true);
}
void loop(){
char whichKey = myKeypad.getKey();
lcd.setCursor(0, 0);
lcd.print("Please Enter ");
lcd.setCursor(0, 1);
lcd.print(" Password");
if(whichKey == '*' || whichKey == '#' || whichKey == 'A' || //define invalid keys
whichKey == 'B' || whichKey == 'C' || whichKey == 'D'){
pozisyon=0;
setLocked (true);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" ** Try again **");
delay(1000);
lcd.clear();
}
if(whichKey == password [pozisyon]){
pozisyon ++;
}
if(pozisyon == 4){
setLocked (false);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("*Welcome*");
lcd.setCursor(0, 1);
lcd.print(" Mr.Arduino");
delay(5000);
lcd.clear();
}
delay(100);
}
void setLocked(int locked){
if(locked){digitalWrite(LED, LOW);
}
else{
digitalWrite(LED, HIGH);
}
}
Keypad pins
keypad left pin to right=Arduino digital pin 0 to 7
LED pins
LED (+) = Arduino digital pin 13
LED (-) = Arduino GND
Libraries:-
- LCD display :-https://github.com/arduino-libraries/LiquidCrystal
- keypad :- https://www.arduinolibraries.info/libraries/keypad
Code:-
#include <LiquidCrystal.h> //include LCD library
#include <Keypad.h> //include keypad library
//define the LED pins
#define LED 13
char* password ="1234"; //create a password
int pozisyon = 0;
const byte rows = 4; //number of the keypad's rows
const byte cols = 4;//number of the keypad's columns
char keyMap [rows] [cols] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins [rows] = {0, 1, 2, 3}; //pins of the keypad
byte colPins [cols] = {4, 5, 6, 7};
Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);
LiquidCrystal lcd (A5, A4, A0, A1, A2, A3); // pins of the LCD.
void setup(){
lcd.begin(16, 2);
pinMode(LED, OUTPUT);
setLocked (true);
}
void loop(){
char whichKey = myKeypad.getKey();
lcd.setCursor(0, 0);
lcd.print("Please Enter ");
lcd.setCursor(0, 1);
lcd.print(" Password");
if(whichKey == '*' || whichKey == '#' || whichKey == 'A' || //define invalid keys
whichKey == 'B' || whichKey == 'C' || whichKey == 'D'){
pozisyon=0;
setLocked (true);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" ** Try again **");
delay(1000);
lcd.clear();
}
if(whichKey == password [pozisyon]){
pozisyon ++;
}
if(pozisyon == 4){
setLocked (false);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("*Welcome*");
lcd.setCursor(0, 1);
lcd.print(" Mr.Arduino");
delay(5000);
lcd.clear();
}
delay(100);
}
void setLocked(int locked){
if(locked){digitalWrite(LED, LOW);
}
else{
digitalWrite(LED, HIGH);
}
}