PASSWORD KEYPAD WITH I2C LCD

keypad pass

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/PASSWORD%20KEYPAD%20WITH%20I2C%20LCD.zip

#include <Password.h>
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <LCD.h>
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE);
LCD *myLCD = &lcd;
Password password = Password(“12345678″); // password
int dlugosc = 8; // length of the password

int ledRed = 11;
int ledGreen = 12;
int buzzer = 13;

int ilosc; // number of clicks

const byte ROWS = 4; // rows
const byte COLS = 4; // cols

char keys[ROWS][COLS] =
{
{‘1′,’2′,’3′,’A’},
{‘4′,’5′,’6′,’B’},
{‘7′,’8′,’9′,’C’},
{‘*’,’0′,’#’,’D’}
};

byte rowPins[ROWS] = {5,4,3,2};
byte colPins[COLS] = {9,8,7,6};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
Serial.begin(9600);
keypad.addEventListener(keypadEvent);
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(buzzer, OUTPUT);

digitalWrite(ledRed, HIGH);
digitalWrite(ledGreen, LOW);

lcd.begin(16, 2);

lcd.setCursor(1,0);
lcd.print(” :Welcome:”);
lcd.setCursor(0,1);
lcd.print(“PLEASE ENTER PIN”);
}

void loop()
{
keypad.getKey();
}
void keypadEvent(KeypadEvent eKey)
{
switch (keypad.getState())
{
case PRESSED:

int i;
for( i = 1; i <= 1; i++ )
{
digitalWrite(buzzer, HIGH);
delay(50);
digitalWrite(buzzer, LOW);
delay(50);
}

Serial.print(“Pressed: “);
Serial.println(eKey);

switch (eKey)
{
/*
case ‘#’:
break;

case ‘*’:
break;
*/

default:
ilosc=ilosc+1;
password.append(eKey);
}
//Serial.println(ilosc);

if(ilosc == 1)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“*_”);
}
if(ilosc == 2)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“**_”);
}
if(ilosc == 3)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“***_”);
}
if(ilosc == 4)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“****_”);
}
if(ilosc == 5)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“*****_”);
}
if(ilosc == 6)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“******_”);
}
if(ilosc == 7)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“*******_”);
}
if(ilosc == 8)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“********”);
}

if(ilosc == dlugosc)
{
delay(250);
checkPassword();
ilosc = 0;
}
}
}

void checkPassword()
{
if (password.evaluate())
{
int i;
for( i = 1; i <= 2; i++ )
{
digitalWrite(buzzer, HIGH);
delay(70);
digitalWrite(buzzer, LOW);
delay(70);
}
ilosc = 0;
//===============Event that want to do if pin right
Serial.println(“Success”);

digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, HIGH);

lcd.clear();
lcd.setCursor(0,1);
lcd.print(” << SUCCESS >>”);
//======================================================
}
else
{
int i;
for( i = 1; i <= 1; i++ )
{
digitalWrite(buzzer, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
delay(200);
}
ilosc = 0;
password.reset();

Serial.println(“Wrong”);

digitalWrite(ledGreen, LOW);
digitalWrite(ledRed, HIGH);

lcd.clear();
lcd.setCursor(0,1);
lcd.print(” << WRONG >>”);
delay(2000);

lcd.clear();
lcd.setCursor(1,0);
lcd.print(” :Welcome:”);
lcd.setCursor(0,1);
lcd.print(“PLEASE ENTER PIN”);
}
}

OTHER CODE

#include <Password.h>
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <LCD.h>
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE);
LCD *myLCD = &lcd;
Password password = Password(“12345678″); // password
int dlugosc = 8; // length of the password

int ledRed = 11;
int ledGreen = 12;
int buzzer = 13;

int ilosc; // number of clicks

const byte ROWS = 4; // rows
const byte COLS = 4; // cols

char keys[ROWS][COLS] =
{
{‘1′,’2′,’3′,’A’},
{‘4′,’5′,’6′,’B’},
{‘7′,’8′,’9′,’C’},
{‘*’,’0′,’#’,’D’}
};

byte rowPins[ROWS] = {5,4,3,2};
byte colPins[COLS] = {9,8,7,6};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
Serial.begin(9600);
keypad.addEventListener(keypadEvent);
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(buzzer, OUTPUT);

digitalWrite(ledRed, HIGH);
digitalWrite(ledGreen, LOW);

lcd.begin(16, 2);

lcd.setCursor(1,0);
lcd.print(” :Welcome:”);
lcd.setCursor(0,1);
lcd.print(“PLEASE ENTER PIN”);
}

void loop()
{
keypad.getKey();
}
void keypadEvent(KeypadEvent eKey)
{
switch (keypad.getState())
{
case PRESSED:

int i;
for( i = 1; i <= 1; i++ )
{
digitalWrite(buzzer, HIGH);
delay(50);
digitalWrite(buzzer, LOW);
delay(50);
}

Serial.print(“Pressed: “);
Serial.println(eKey);

switch (eKey)
{
/*
case ‘#’:
break;

case ‘*’:
break;
*/

default:
ilosc=ilosc+1;
password.append(eKey);
}
//Serial.println(ilosc);

if(ilosc == 1)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“*_”);
}
if(ilosc == 2)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“**_”);
}
if(ilosc == 3)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“***_”);
}
if(ilosc == 4)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“****_”);
}
if(ilosc == 5)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“*****_”);
}
if(ilosc == 6)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“******_”);
}
if(ilosc == 7)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“*******_”);
}
if(ilosc == 8)
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” < PIN >”);
lcd.setCursor(0,1);
lcd.print(“********”);
}

if(ilosc == dlugosc)
{
delay(250);
checkPassword();
ilosc = 0;
}
}
}

void checkPassword()
{
if (password.evaluate())
{
int i;
for( i = 1; i <= 2; i++ )
{
digitalWrite(buzzer, HIGH);
delay(70);
digitalWrite(buzzer, LOW);
delay(70);
}
ilosc = 0;
//===============Event that want to do if pin right
Serial.println(“Success”);

digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, HIGH);

lcd.clear();
lcd.setCursor(0,1);
lcd.print(” << SUCCESS >>”);
password.reset();
delay(3000);
digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, LOW);
lcd.clear();
lcd.setCursor(1,0);
lcd.print(” :Welcome:”);
lcd.setCursor(0,1);
lcd.print(“PLEASE ENTER PIN”);
//======================================================
}
else
{
int i;
for( i = 1; i <= 1; i++ )
{
digitalWrite(buzzer, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
delay(200);
}
ilosc = 0;
password.reset();

Serial.println(“Wrong”);

digitalWrite(ledGreen, LOW);
digitalWrite(ledRed, HIGH);

lcd.clear();
lcd.setCursor(0,1);
lcd.print(” << WRONG >>”);
delay(2000);

lcd.clear();
lcd.setCursor(1,0);
lcd.print(” :Welcome:”);
lcd.setCursor(0,1);
lcd.print(“PLEASE ENTER PIN”);
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s