KEYPAD LOCK PASSWORD

keypad pass 1

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/Keypad%20Lock.zip

/*

and press “#” than enter your password and press*. The LED will turn ON and will OFF.

*/

#include <Password.h> //http://playground.arduino.cc/uploads/Code/Password.zip //tells to use password library

#include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip //tells to use keypad library

Password password = Password( “1234” ); //password to unlock, can be changed

const byte ROWS = 4; //four rows

const byte COLS = 4; //four columns

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}; //connect to the row pinouts of the keypad

byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad

// Create the Keypad

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

void setup(){

Serial.begin(9600);

delay(200);

pinMode(13, OUTPUT);

keypad.addEventListener(keypadEvent); //add an event listener for this keypad

}

void loop(){

keypad.getKey();

}

void keypadEvent(KeypadEvent eKey){

switch (keypad.getState()){

case PRESSED:

Serial.print(“Enter:”);

Serial.println(eKey);

delay(10);

switch (eKey){

case ‘*’: checkPassword(); delay(1); break;

case ‘#’: password.reset(); delay(1); break;

default: password.append(eKey); delay(1);

}

}

}

void checkPassword(){

if (password.evaluate()){ //if password is right open

Serial.println(“Accepted”);

digitalWrite(13, HIGH);//turn on

delay(5000); //wait 5 seconds

digitalWrite(13, LOW);// turn off

}else{

Serial.println(“Denied”); //if passwords wrong keep locked

digitalWrite(13, LOW);//turn off

}

}

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