Instructables
Picture of 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



 
Remove these adsRemove these ads by Signing Up

Step 1: Wire the LCD to the Arduino

Picture of Wire the LCD to the Arduino
DSC00028.JPG
DSC00041.JPG
lcd_photo.JPG
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! :)
1-40 of 47Next »
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

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 :)

joemhar9 months ago

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

ultron joemhar6 months ago

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");

}

}

bsmith1508 months ago

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

wafeez10 months ago
sorry..but i cant open the link given
all of it
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 !
paan24311 year ago
can u email me the systematic diagram for circuit and the programming for arduino. ...in hurry to complete final project..im from seoul.
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.
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.
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.
Adam003161 year ago
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
markie1 year ago
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
markie1 year ago
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
razvan_iycdi (author)  markie1 year ago
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!
Thats just the problem.. all the files are there :O
So im a bit confused >.<
arduino.JPG
razvan_iycdi (author)  markie1 year ago
Including keypad.h and keypad.c ?
Yes, keypad.h & keypad which is a CCP file
markie markie1 year ago
i mean CPP
razvan_iycdi (author)  markie1 year ago
Hmmm. Could you paste in your code?
#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();
}
}

markie1 year ago
This is AWESOME!!! After i figured out my keypad, it worked just fine!
Thank you very much :D
razvan_iycdi (author)  markie1 year ago
Hey! I'm glad you got it working and that you liked it.
Thank's for checking it out.

Cheers!
Did you buy the lcd screen at sparfun and if so, witch one is it?
razvan_iycdi (author)  jguillemette11 year ago
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
Thanks for all this great information! I had a question regarding the buttonPin input. What is it, and how did you determine it to be 7?
FYI, I'm using the matrix keypad made for Arduino by Adafruit, http://adafru.it/419 so I'm not sure if it needs the 5V that yours needed.
razvan_iycdi (author)  climbermaniac921 year ago
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.
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)
razvan_iycdi (author)  jguillemette11 year ago
that's just the display type...
virus35472 years ago
Thank you for this great tutorial. I am having a problem compiling the code. The arduino IDE is outputting this error:

In file included from arduino.cpp:6:
C:\Users\Kids\Documents\arduino-1.0-windows\arduino-1.0\libraries\Password/Password.h:33:22: error: WProgram.h: No such file or directory
In file included from arduino.cpp:6:
C:\Users\Kids\Documents\arduino-1.0-windows\arduino-1.0\libraries\Password/Password.h:61: error: 'byte' does not name a type
In file included from arduino.cpp:7:
C:\Users\Kids\Documents\arduino-1.0-windows\arduino-1.0\libraries\Keypad/Keypad.h:50: error: 'byte' does not name a type
C:\Users\Kids\Documents\arduino-1.0-windows\arduino-1.0\libraries\Keypad/Keypad.h:51: error: 'byte' does not name a type
C:\Users\Kids\Documents\arduino-1.0-windows\arduino-1.0\libraries\Keypad/Keypad.h:63: error: 'byte' has not been declared
C:\Users\Kids\Documents\arduino-1.0-windows\arduino-1.0\libraries\Keypad/Keypad.h:63: error: 'byte' has not been declared
C:\Users\Kids\Documents\arduino-1.0-windows\arduino-1.0\libraries\Keypad/Keypad.h:63: error: 'byte' has not been declared
C:\Users\Kids\Documents\arduino-1.0-windows\arduino-1.0\libraries\Keypad/Keypad.h:63: error: 'byte' has not been declared
C:\Users\Kids\Documents\arduino-1.0-windows\arduino-1.0\libraries\Keypad/Keypad.h:78: error: ISO C++ forbids declaration of 'byte' with no type
C:\Users\Kids\Documents\arduino-1.0-windows\arduino-1.0\libraries\Keypad/Keypad.h:78: error: expected ';' before '*' token
C:\Users\Kids\Documents\arduino-1.0-windows\arduino-1.0\libraries\Keypad/Keypad.h:79: error: ISO C++ forbids declaration of 'byte' with no type
C:\Users\Kids\Documents\arduino-1.0-windows\arduino-1.0\libraries\Keypad/Keypad.h:79: error: expected ';' before '*' token

Does anyone know how to fix this? It looks like a problem within the library. Thank you.
razvan_iycdi (author)  virus35472 years ago
Hey,
Thanks for trying my tutorial.
From what you said, it looks like your files are not in the same place as they should be... Thy reinstalling the Arduino IDE and then put all the libraries in the correct folder and try again.
Let me know how it goes.

Good luck!
Thank you for the help. I completely reinstalled arduino from scratch (version 1.0.1) and put all of the libraries in. Unfortunately, the errors are still there. Do you have any other ideas to fix the error? Thank you.
Thank you very much. I realized that there was a configuration error. Everything compiles now.
i have made this code without using lcd screen...i used the keypad only...cause arduino uno doesn't have enough pins...but there's no output...where is the problem?? is the code right??

#include

#include

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] = {2,3,4,9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {10,11,12}; //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);

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);



}

//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();
}
}
razvan_iycdi (author)  asmaa mahmoud2 years ago
Use this:

#include
#include

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);

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);
}

//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
password.reset(); //resets password after correct entry
delay(600);
}


else{
digitalWrite(ledPin,LOW);
password.reset(); //resets password after INCORRECT entry
delay(600);
}
}
razvan_iycdi (author)  razvan_iycdi2 years ago
make sure you have the libraries where they are supposed to be.
only import Password.h and Keypad.h
roachburn2 years ago
Thank you for this awesome instructable! I managed to use this with an Uno by driving the lcd with a 74hc595 shift register.
I used LiquidCrystal_SR.h Library which can be found here:

https://bitbucket.org/fmalpartida/new-liquidcrystal/overview

Also check out this post for more info on the shift register Library:

http://arduino.cc/forum/index.php/topic,90526.0.html



#include <Keypad.h>

#include <LiquidCrystal_SR.h>
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] = {5, 6, 7, 8}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 10, 11}; //connect to the column pinouts of the keypad
const int buttonPin = 12;
int buttonState = 0;

#define  DATAPIN  2
#define  CLOCKPIN 4
#define  STROBEPIN 3
#define  MAXCOLUMNS  16
#define  MAXLINES  2
#define ledPin 13
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
LiquidCrystal_SR lcd(DATAPIN, CLOCKPIN, STROBEPIN);

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  // set up the LCD's number of rows and columns:
  lcd.begin(MAXCOLUMNS, MAXLINES);
  digitalWrite(ledPin, LOW);
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();
}
}
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();
}
}


I get an error when I run this code. the error is: 'Password' does not name a type
razvan_iycdi (author)  fekrheusa2 years ago
That's because you did not import the password library.
1-40 of 47Next »