Introduction: Password Lock With Arduino

This instructable will show you how to make a pass-code lock system using the Arduino Mega board.
What you will need:
--->one Arduino Mega (the arduino uno or duemilianove does not have enough digital pins for this project)
--->one LCD module
--->one Keypad
--->one Battery pack (or you can use the USB cable and PC power)
--->one 10K Ohm potentiometer
--->four 10K Ohm resistors
---> Breadboard
---> hookup wire



Step 1: Wire the LCD to the Arduino

The LCD module has 16 pins.
First of all, connect pins 1 and 16 of the LCD to the ground rail on the Breadboard
Then connect pins 2 and 15 of the LCD to the +5v rail on the breadboard
Now connect the ground rail(should be blue) of the breadboard to a ground pin on the Arduino; 
Connect the +5v rail of the breadboard(this one is red) to one of the +5v pins on the Arduino board.

Now comes the contrast potentiometer which has to be connected to pin 3 of the LCD.
The potentiometer will have 3 pins. Take the middle pin and connect it to pin 3 of the arduino with hookup wire. Connect the othere two pins one to +5v and the other to GND(ground). The order does not matter.

Now let's do a test: power up the arduino. The LCD should light up. If it does then Great! If the LCD does not light up then turn off the power and check the wires. 

Never change, move, or take out wires from the circuit board when the Arduino is powered up. You may permanently damage the Arduino.

If the light works rotate the potentiometer all the way to the right and all the way to the left until you see 2 rows of black squares. That's the contrast. 

Now take out the power and let's hook up the LCD to the Arduino with the signal wires so we can display something on it.
Ready? Let's go!

Connect the pins as follows:
LCD Pin 4   --> Arduino Pin 2
LCD Pin 5   --> Arduino Pin 3
LCD Pin 6   --> Arduino Pin 4
LCD Pin 11 --> Arduino Pin 9
LCD Pin 12 --> Arduino Pin 10
LCD Pin 13 --> Arduino Pin 11
LCD Pin 14 --> Arduino Pin 12

And that should do it for the LCD circuit.
A test code for the the LCD: temporary.

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2,3,4,9,10,11,12);

void setup() {
  // set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}




Copy and paste it in an arduino environment window, make sure you have the board and serial port set correct and click UPLOAD after you plug in the usb with the arduino.
You will see the TX and RX led's blinking, that means the code is going to the arduino.
push the reset botton once on the arduino, tune the contrast, and you should see Hello World displayed. 
Congratulations! You've got the LCD working! :)

Step 2: Wire the Keypad to the Arduino

OK. Now that we're done with the LCD and we got it working, it's time to connect the keypad to the arduino. This can be a little tricky depending on what type of keyboard you are using. In my case, I used a 3x4 keypad that I had for some time. 
If you have a keyboard that is made especially for connecting to an arduino, then it's easy. You just look at the datasheet for it and it tells you exactly how to hook it up.
If you have a keypad and you have no datasheet for it then hang on cause I was in the same situation.
Mine had on the back a diagram that shows you which pins are connected together when you press a certain key.
If you don't have that, you will have to use a multimeter and figure out which pins are connected together when you press each key. 
To do that, take your multimeter and set it on continuity(the diode symbol).
Then put the test leads on pins 1 and 2 of the keypad. Now press every key until you get continuity. 
Take paper and a pen and write down the key(ex:1, 2, #) and the two pins(ex: 6[1;2]). 
Do so for every key until you get all of them figured out.
Make a table:
1=1+5
2=1+6
3=1+7
4=2+5
5=2+6
6=2+7
7=3+5
8=3+6
9=3+7
*=4+5
0=4+6
#=4+7

That is what I got.
Whatever you get, if you write down the keys in that order you will see the logic in it.
From my table I can see that the row pins are 1,2,3,4; and the column pins are 5,6,7.

Now plug the pins of the keypad in a breadboard and let's start connecting it.
Connect the pins for rows 2 and 3( in my case pins 2 and 3) to +5v through 10K Ohm resistors. Do the same with the pins for column 1 and 3 pins( in my case pins 5 and 7).

If you have an arduino mega, connect the keypad as follows:
Keypad pin row1--> arduino pin 25
Keypad pin row2--> arduino pin 24
Keypad pin row3--> arduino pin 23
Keypad pin row4--> arduino pin 22
Keypad pin column1 --> arduino pin 28
Keypad pin column2 --> arduino pin 27
Keypad pin column3 --> arduino pin 26

(The arduino uno does not have enough digital pins so it does not fit this project.)

That should do it for the keypad. :) we're one step closer to finish. Hang in there. :) Almost done.




Step 3: Preparations for the Code

Before we put in the final code we have to make some modifications.
https://docs.google.com/leaf?id=0B8GceIlOmvRoNWZmNWExYTMtYjVmNS00MzE5LWFlMWQtNDM3MTY1MTcyZTUx&hl=en_US

G
o to the link above and download the libraries: keypad and password.
They are two files. take the files and put them in /Arduino/Libraries.

if the download does not work for bizarre reasons, go to:
 
http://arduino.cc/playground/uploads/Code/Keypad.zip

http://arduino.cc/playground/uploads/Code/Password.zip


Step 4: Code

Now it's time for the code.
Make sure you have all the wires in place and connect the USB cable.
Upload the following code to the arduino. Copy and paste it in the arduino window just like last time.

#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(2,3,4,9,10,11,12);
Password password = Password( "4321" );
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3',},
  {'4','5','6',},
  {'7','8','9',},
  {'*','0',' ',}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {25, 24, 23, 22}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {28, 27, 26}; //connect to the column pinouts of the keypad
const int buttonPin = 7;
int buttonState = 0;

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

#define ledPin 13

void setup(){
   pinMode(buttonPin, INPUT);
lcd.begin(16, 2);
digitalWrite(ledPin, LOW); // sets the LED on
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
keypad.setDebounceTime(250);
}

void loop(){
keypad.getKey();
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
lcd.clear();
}
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.print(eKey);
switch (eKey){
case ' ': guessPassword(); break;
default:
password.append(eKey);
}
}}

void guessPassword(){
if (password.evaluate()){
digitalWrite(ledPin,HIGH); //activates garaged door relay
delay(500);
digitalWrite(ledPin,LOW); //turns off door relay after .5 sec
lcd.print("VALID PASSWORD "); //
password.reset(); //resets password after correct entry
delay(600);
lcd.print("Welcome");
delay(2000);
lcd.clear();
}


else{
digitalWrite(ledPin,LOW);
lcd.print("INVALID PASSWORD ");
password.reset(); //resets password after INCORRECT entry
delay(600);
lcd.clear();
}
}



Give it a test: type 4321 then press #.
You should see the message VALID PASSWORD    Welcome

After that the LED on the arduino board will light up for a short time. you can put a lock, or a solenoid instead of the led and there you have it: The Arduino Passcode lock 


If you have any problems or questions regarding this instructable, feel free to post a comment. I will answer as soon as I can.Also, if you like the project, consider voting it in the following contests:

https://www.instructables.com/contest/makeitmove/?show=ENTRIES
https://www.instructables.com/contest/toy/?show=ENTRIES
https://www.instructables.com/contest/micro2/?show=ENTRIES
Thanks for reading this 'till the end and I hope you liked it.

Comments

author
TECHMASTERJOE made it!(author)2011-09-19

you can use a arduino uno with not a lot more work just shift in the keypad and or shift out the lcd
try it sometime
i have my uno driving 644 pins (leds)
2X 20x4 lcd's
2 keypads
and about 10 buttons all over the house

author
AbolfazlN1 made it!(author)2016-10-22

Hey Everyone


I have a question about my project and I'll really appreciate any help you can give,

I'm going to programming a software in order to automatically open up 250 doors with FINGERPRINT SCANNER, I mean I've 250 members in a gym and I want to recognize any of them by their fingerprint and then open their related door wardrobe.
So the question is, I don't know after verifying any individual person and understanding the related door, how can I command to the doors to open?
Let me clarify the sentence, Arduino have 16 pins as output and I've 250 doors to control.
I know it's completely ridiculous to dedicate 250 pins to 250 doors but I don't know how to overcome this problem and reduce the pins number!

Thank you in advance for your attention to this matter.

Many thanks
Abolfazl

author
JakeH98 made it!(author)2016-11-28

Try using some shift registers. Its either those or another microprocessor(could be an arduino) in serial. You could get 256 pins from 16 bit Serial in Parallel out shift register provided you can make 16 serial connections. I would recommend looking for a controller that uses UART Bus.

I hope you find a solution soon!.

Have a good day.

author
GeraljoyV made it!(author)2016-07-16

may i have the schematic diagram of your circuit..,tnx:)

author
Giedrius%C5%BD made it!(author)2016-06-10

What you used pin 7 for (buttonPin)?

author
MuhamadP1 made it!(author)2016-06-08

how to change input password with keypad (replace current password with new one), I have this problem and I can't solve it. Can you help me ?

author
AnkurC8 made it!(author)2016-06-06

What is buttonpin in th Code..?

author
Stiffy2000 made it!(author)2016-06-02

What is the recommended resistance for the potentiometer? I'm thprying to make it more compact.

author
Stiffy2000 made it!(author)2016-06-02

I meant trying

author
EceE2 made it!(author)2015-09-07

i am getting error in the code where am i wrong?? i have a mac.. can some one please post the correct version of this code! i need to submit my assignment

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

#include <Keypad.h>

//constants for LEDs

int greenLED = 12;

int redLED = 13;

//set our code

char* ourCode = "1234";

int currentPosition = 0;

//define the keyboard

const byte rows = 4;

const byte cols = 4;

char keys[rows][cols] = {

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},

{'*','0','#','D'},

};

byte rowPins[rows]= {11,10,9,8};

byte colPins[cols]= {7,6,5,4};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);

LiquidCrystal_I2C lcd(0x3F,20,4); // Set the LCD I2C address

#define BACKLIGHT_PIN 13

void setup()

{

lcd.init(); // initialize the lcd

//lcd.init();

// Print a message to the LCD.

lcd.backlight();

displayCodeEntryScreen();

//setup and turn off both LEDs

pinMode(redLED, OUTPUT);

pinMode(greenLED, OUTPUT);

digitalWrite(redLED, LOW);

digitalWrite(greenLED, LOW);

}

void loop(){

int l;

char key = keypad.getKey();

if (int(key) != 0) {

lcd.setCursor(14,3);

lcd.print(" . ");

else,

for(l=0; l<=currentPosition; ++l)

{

lcd.setCursor(14,3);

lcd.print("*");

}

if (key == ourCode[currentPosition])

{

++currentPosition;

if (currentPosition == 4)

{

unlockDoor();

currentPosition = 0;

}

}

}

void invalidCode()

{

digitalWrite(redLED, HIGH);

clearScreen();

lcd.setCursor(0,0);

lcd.print("***************");

lcd.setCursor(0,1);

lcd.print("** ACCESS DENIED! **");

lcd.setCursor(0,2);

lcd.print("** INVALID CODE **");

lcd.setCursor(0,3);

lcd.print("***************");

delay(5000);

digitalWrite(redLED, LOW);

displayCodeEntryScreen();

}

void unlockDoor()

{

digitalWrite(greenLED, HIGH);

clearScreen();

lcd.setCursor(0,0);

lcd.print("***************");

lcd.setCursor(0,1);

lcd.print("** ACCESS GRANTED! **");

lcd.setCursor(0,2);

lcd.print("** WELCOME **");

lcd.setCursor(0,3);

lcd.print("***************");

//add any code to unlock the door here

delay(5000);

digitalWrite(greenLED, LOW);

displaCodeEntryScreen();

}

void displayCodeEntryScreen()

{

clearScreen();

lcd.setCursor(0,0);

lcd.print("Let's Make It Secret");

lcd.setCursor(0,1);

lcd.print("Code Project...");

lcd.setCursor(0,2);

lcd.print("Enter Secret Code:");

}

void clearScreen()

{

lcd.setCursor(0,0);

lcd.print(" ");

lcd.setCursor(0,1);

lcd.print(" ");

lcd.setCursor(0,2);

lcd.print(" ");

lcd.setCursor(0,3);

lcd.print(" ");

}

}

author
Stiffy2000 made it!(author)2016-06-02

Did you try to indent your code?

author
nuffateeya made it!(author)2016-03-22

i have problem with this error.. can you help me!!

292d8d01-0239-41a4-abdf-7bf67978ef9f.jpg
author
QudratullahS made it!(author)2016-01-21

Hi,

Can i get the Schematic Diagram of this project please ? as i am new to this arduino seystems... Thanks!!1!1!

author
rnavos made it!(author)2015-12-29

hi..can i use a tack switches instead of a keypad as an improvised keypad for the password?

author
lusifar made it!(author)2015-09-14

Can you help me to do this as a user defined or changeable password lock...

author
abidjamalkhan made it!(author)2015-04-08

Easy way to Add arduino Library in to Proteus
http://www.electronicslovers.com/2015/03/how-to-ad...

author
abhishek.k.c.73 made it!(author)2015-02-13

HI.. Iam new here.. I have an idea of getting the passcode from the user. Instead of setting the code in the program is there any way that it can be obtained from the user.. if so can i get the code for it.. Thanks in advance

author
abhishek.k.c.73 made it!(author)2015-02-13

HI.. Iam new here.. I have an idea of getting the passcode from the user. Instead of setting the code in the program is there any way that it can be obtained from the user.. if so can i get the code for it.. Thanks in advance

author
SourabrataB made it!(author)2015-02-08

Hi ,my fellow friends

I want u all to inform that u can use a 10 K ohm variable resistor instead of key pad.

u can asign a variable for the mapped value of the variable resistor. For example -

int x = analogRead ( 1 );

x = map(x, 0, 1023, 0, 28);

this is for A-Z letter map down. We can use if and else or if statements for value of each map. For example-

if ( x = 0 )

{

lcd.print ( A);

}

this will make it support Arduino uno.

note : I am a student of class 7 who is very interested in semiconductor ,ic,

and electronics engineering. if mistakes are any pls write it to me. I am from India.

author
ppaulerrol made it!(author)2015-01-31

Nc instructions!!

can you help me with my project .. i already have GSM module can you help me how will i connect it into your device??.. if the passwords denied the person will receive a sms that something is opening the door/device..

they have only 3 trials in the password.. then it will send..

so bad english.. >_<

author
DarrenN2 made it!(author)2015-01-26

what type of lock can I put on it and could you give me the code for it, because im just a novice at arduino, kind of

author
alexloh0430 made it!(author)2014-11-16

Hi, I'm new here and first time using Arduino Mega. I have some problems at the first step, which is my LCD doesn't displays black squares. Is my LCD got any problems or spoiled? I have redo many times already. It is also the same.

author
rafhanahs made it!(author)2014-11-30

Have you tried adjusting the potentiometer?

author
farah.jabaly made it!(author)2014-10-17

Hello ,

I tried to do this project but when I connect the LCD and uploaded the code ,, nothing appeared on the screen I don't know why ? :(

I need to make a password system and let the user choose a system for example : system 1 or system 2 ,, If he pressed (1) he will move to system1 and if he pressed 2 he will move to system 2 ,,, I need your help please

Thanks in advance :)

author
joemhar made it!(author)2014-01-23

What if i add a servo that will open if the password is valid..what will be the overall coding..btw nc tutorial!!

author
ultron made it!(author)2014-03-29

i used arduino uno with this code it need a litlle bit of more work but here you go

#include <Password.h>

#include <Keypad.h>

#include <LiquidCrystal_I2C.h>

#include <Wire.h>

#include <Servo.h>

Servo myservo;

int pos = 0;

Password password = Password( "1234" );

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

const byte ROWS = 4;

const byte COLS = 4;

char keys[ROWS][COLS] = {

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},

{'*','0','#','D'}

};

byte rowPins[ROWS] = {11, 10, 8, 7};

byte colPins[COLS] = {6, 5, 4, 3};

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

void setup()

{

myservo.attach(9);

lcd.begin(16, 2);

lcd.print(" Enter Password");

Serial.begin(9600);

keypad.addEventListener(keypadEvent);

keypad.setDebounceTime(250);

}

void loop()

{

lcd.setCursor(0, 1);

keypad.getKey();

}

void keypadEvent(KeypadEvent keyPress)

{

switch (keypad.getState())

{

case PRESSED:

lcd.print(keyPress);

switch (keyPress)

{

case '#':

checkPassword();

break;

case '*':

password.reset();

lcd.clear();

lcd.setCursor(0,0);

lcd.print(" Enter Password");

break;

case 'A':

lcd.clear();

lcd.setCursor(0,0);

lcd.print("LASER:ON");

delay(2000);

lcd.clear();

lcd.setCursor(0,0);

lcd.print(" Enter Password");

break;

case 'B':

lcd.clear();

lcd.setCursor(0,0);

lcd.print("LASER:OFF");

delay(2000);

lcd.clear();

lcd.setCursor(0,0);

lcd.print(" Enter Password");

break;

case 'C':

lcd.clear();

lcd.setCursor(0,0);

lcd.print("LOCKDOWN");

delay(2000);

for(pos = 180; pos>=0; pos-=1)

{

myservo.write(pos);

delay(3);

}

lcd.clear();

lcd.setCursor(0,0);

lcd.print(" Enter Password");

break;

default:

password.append(keyPress);

}

}

}

void checkPassword(){

if (password.evaluate())

{

lcd.clear();

lcd.setCursor(0,0);

lcd.print("*****ACCESS*****");

lcd.setCursor(0,1);

lcd.print("*****GRANTED****");

password.reset();

delay(100);

for(pos = 0; pos < 180; pos += 1)

{

myservo.write(pos);

delay(3);

}

delay(2000);

password.reset();

lcd.clear();

lcd.setCursor(0,0);

lcd.print(" Enter Password");

}

else

{

lcd.setCursor(0,0);

lcd.print("*****ACCESS*****");

lcd.setCursor(0,1);

lcd.print("*****DENIED*****");

delay(10);

password.reset();

delay(2000);

lcd.clear();

lcd.setCursor(0,0);

lcd.print(" Enter Password");

}

}

author
bsmith150 made it!(author)2014-01-24

the code is not working for me i press upload and it said that "const byte COLS = 3; // Three columns" was declared void need help

author
wafeez made it!(author)2013-12-10

sorry..but i cant open the link given
all of it

author
DanGutierres made it!(author)2013-10-17

Hello razvan, you did an excellent job with this project.Thank you for sharing! Could you tell me something?
I'm trying to make it using a Arduino Uno, but i'm having some trouble using the 74HC595. Did you or somebody else found a way to make it work with the project?
I already tried the LiquidCrystal_SR library ( the one that uses the CI) but the display dont receive the correct information. Do you have any ideia?
Thanks !

author
paan2431 made it!(author)2013-09-30

can u email me the systematic diagram for circuit and the programming for arduino. ...in hurry to complete final project..im from seoul.

author
rprihartono made it!(author)2013-06-26

hi, I'm trying to make your project with an additional servo, the way it works is if the password is correct then the servo will be active. Can you give me the code. you can post them on this site or send an email to me (obots_beghenk@yahoo.co.id).
I was expecting your help and I will be very thankful to you.

author
rprihartono made it!(author)2013-06-26

hi, I'm trying to make your project with an additional servo, the way it works is if the password is correct then the servo will be active. Can you give me the code. you can post them on this site or send an email to me (obots_beghenk@yahoo.co.id).
I was expecting your help and I will be very thankful to you.

author
rprihartono made it!(author)2013-06-26

hi, I'm trying to make your project with an additional servo, the way it works is if the password is correct then the servo will be active. Can you give me the code. you can post them on this site or send an email to me (obots_beghenk@yahoo.co.id).
I was expecting your help and I will be very thankful to you.

author
Adam00316 made it!(author)2013-04-13

Hi , im new to arduino and i have a class project for it , can anyone please help me step by step on how to do something nice ?
Thanks in advance

author
markie made it!(author)2013-04-03

Hi, i got the whole thing working but i have a question. Each time i press a key, i want to see this (*). So when you type in your code (Example): 1234A it shows ***** on the lcd. I have experimented with (eKey++); but i could not get it working :(
I hope you can help me!

Mark

author
markie made it!(author)2013-03-13

Hi again, i'm getting this error when i started the program for the second time :(
I only extracted the password.h & keypad.h to Arduino/libraries.
Can you help me?


sketch_mar13a:1: error: variable or field 'keypadEvent' declared void
sketch_mar13a:1: error: 'KeypadEvent' was not declared in this scope
sketch_mar13a:4: error: 'Password' does not name a type
sketch_mar13a:21: error: 'Keypad' does not name a type
sketch_mar13a.cpp: In function 'void setup()':
sketch_mar13a:30: error: 'keypad' was not declared in this scope
sketch_mar13a:30: error: 'keypadEvent' was not declared in this scope
sketch_mar13a.cpp: In function 'void loop()':
sketch_mar13a:35: error: 'keypad' was not declared in this scope
sketch_mar13a.cpp: At global scope:
sketch_mar13a:43: error: variable or field 'keypadEvent' declared void
sketch_mar13a:43: error: 'KeypadEvent' was not declared in this scope

author
razvan_iycdi made it!(author)2013-03-13

Hello again.
It looks like your libraries (Keypad and Password) are not in the right place or some of their components are missing. In the case of the Keypad library, you should have a folder called Keypad in your /Arduino/libraries. This folder should have Keypad.h and Keypad.c inside it. It may also have a folder called Examples inside it, but that's not relevant to your case. The same applies to Password. Just make sure you have that. If you don't know where the files went, just delete the Keypad and Password folders and download them again.

What the Arduino is telling you in that error message is: "What keypad?! There's a keypad on me?! I don't know how to do that.".

Let me know if that works for you.

Cheers!

author
markie made it!(author)2013-03-13

Thats just the problem.. all the files are there :O
So im a bit confused >.<

arduino.JPG
author
razvan_iycdi made it!(author)2013-03-13

Including keypad.h and keypad.c ?

author
markie made it!(author)2013-03-13

Yes, keypad.h & keypad which is a CCP file

author
markie made it!(author)2013-03-13

i mean CPP

author
razvan_iycdi made it!(author)2013-03-13

Hmmm. Could you paste in your code?

author
markie made it!(author)2013-03-13

#include
#include
#include
LiquidCrystal lcd(2,3,4,9,10,11,12);
Password password = Password( "4321" );
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3',},
{'4','5','6',},
{'7','8','9',},
{'*','0',' ',}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {25, 24, 23, 22}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {28, 27, 26}; //connect to the column pinouts of the keypad
const int buttonPin = 7;
int buttonState = 0;

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

#define ledPin 13

void setup(){
pinMode(buttonPin, INPUT);
lcd.begin(16, 2);
digitalWrite(ledPin, LOW); // sets the LED on
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
keypad.setDebounceTime(250);
}

void loop(){
keypad.getKey();
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
lcd.clear();
}
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.print(eKey);
switch (eKey){
case ' ': guessPassword(); break;
default:
password.append(eKey);
}
}}

void guessPassword(){
if (password.evaluate()){
digitalWrite(ledPin,HIGH); //activates garaged door relay
delay(500);
digitalWrite(ledPin,LOW); //turns off door relay after .5 sec
lcd.print("VALID PASSWORD "); //
password.reset(); //resets password after correct entry
delay(600);
lcd.print("Welcome, Razvan");
delay(2000);
lcd.clear();
}


else{
digitalWrite(ledPin,LOW);
lcd.print("INVALID PASSWORD ");
password.reset(); //resets password after INCORRECT entry
delay(600);
lcd.clear();
}
}

author
markie made it!(author)2013-03-12

This is AWESOME!!! After i figured out my keypad, it worked just fine!
Thank you very much :D

author
razvan_iycdi made it!(author)2013-03-12

Hey! I'm glad you got it working and that you liked it.
Thank's for checking it out.

Cheers!

author
jguillemette1 made it!(author)2013-02-27

Did you buy the lcd screen at sparfun and if so, witch one is it?

author
razvan_iycdi made it!(author)2013-02-27

I did not buy that LCD from Sparkfun. That is a generic LCD that I bought about three or for years ago from some website when I got my first breadboard Arduino kit.
If you want to buy one from Sparkfun, I would recommend something like this:
https://www.sparkfun.com/products/10862

author
razvan_iycdi made it!(author)2013-02-26

Hey. Sorry for such a late response. I've been busy with school and forgot to check Instructables. buttonPin is just the name I gave to the pin that reads the state of the button [HIGH or LOW]. You can use any number for it. It is not related to the keypad, it;s an actual button separate from the keypad itself.

author
jguillemette1 made it!(author)2013-02-26

I see you use alot ”liquidcrystal” in your codes and is it because that is the company or the name of the lcd screen or you just have to wright that ( im kinda like a newbie with thar kind of stuff)

author
razvan_iycdi made it!(author)2013-02-26

that's just the display type...