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:

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! :)
you can use a arduino uno with not a lot more work just shift in the keypad and or shift out the lcd<br>try it sometime <br>i have my uno driving 644 pins (leds)<br>2X 20x4 lcd's<br>2 keypads<br>and about 10 buttons all over the house<br>
<p>Hey Everyone</p><p><br>I have a question about my project and I'll really appreciate any help you can give,<br><br>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.<br>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?<br>Let me clarify the sentence, Arduino have 16 pins as output and I've 250 doors to control.<br>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!<br><br>Thank you in advance for your attention to this matter.<br><br>Many thanks<br>Abolfazl</p>
<p>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.</p><p>I hope you find a solution soon!.</p><p>Have a good day.</p>
<p>may i have the schematic diagram of your circuit..,tnx:)</p>
<p>What you used pin 7 for (buttonPin)?</p>
<p>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 ? </p>
<p>What is buttonpin in th Code..?</p>
<p>What is the recommended resistance for the potentiometer? I'm thprying to make it more compact.</p>
<p>I meant trying</p>
<p>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 </p><p>#include &lt;Wire.h&gt;</p><p>#include &lt;LiquidCrystal_I2C.h&gt;</p><p>#include &lt;Keypad.h&gt;</p><p>//constants for LEDs</p><p>int greenLED = 12;</p><p>int redLED = 13;</p><p>//set our code</p><p>char* ourCode = &quot;1234&quot;;</p><p>int currentPosition = 0;</p><p> //define the keyboard</p><p> const byte rows = 4;</p><p> const byte cols = 4;</p><p> char keys[rows][cols] = {</p><p> {'1','2','3','A'},</p><p> {'4','5','6','B'},</p><p> {'7','8','9','C'},</p><p> {'*','0','#','D'},</p><p> };</p><p> byte rowPins[rows]= {11,10,9,8};</p><p> byte colPins[cols]= {7,6,5,4};</p><p> Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);</p><p>LiquidCrystal_I2C lcd(0x3F,20,4); // Set the LCD I2C address</p><p>#define BACKLIGHT_PIN 13</p><p> void setup()</p><p> {</p><p> lcd.init(); // initialize the lcd</p><p> //lcd.init();</p><p> // Print a message to the LCD.</p><p> lcd.backlight();</p><p> displayCodeEntryScreen();</p><p> //setup and turn off both LEDs</p><p> pinMode(redLED, OUTPUT);</p><p> pinMode(greenLED, OUTPUT);</p><p> digitalWrite(redLED, LOW);</p><p> digitalWrite(greenLED, LOW);</p><p> }</p><p>void loop(){</p><p> int l;</p><p> char key = keypad.getKey();</p><p> if (int(key) != 0) {</p><p> lcd.setCursor(14,3);</p><p> lcd.print(&quot; . &quot;);</p><p>else,</p><p> for(l=0; l&lt;=currentPosition; ++l)</p><p> {</p><p> lcd.setCursor(14,3);</p><p> lcd.print(&quot;*&quot;);</p><p> }</p><p> if (key == ourCode[currentPosition])</p><p> {</p><p> ++currentPosition;</p><p> if (currentPosition == 4)</p><p> {</p><p> unlockDoor();</p><p> currentPosition = 0;</p><p> }</p><p> }</p><p> }</p><p> void invalidCode()</p><p> {</p><p> digitalWrite(redLED, HIGH);</p><p> clearScreen();</p><p> lcd.setCursor(0,0);</p><p> lcd.print(&quot;***************&quot;);</p><p> lcd.setCursor(0,1);</p><p> lcd.print(&quot;** ACCESS DENIED! **&quot;);</p><p> lcd.setCursor(0,2);</p><p> lcd.print(&quot;** INVALID CODE **&quot;);</p><p> lcd.setCursor(0,3);</p><p> lcd.print(&quot;***************&quot;);</p><p> delay(5000);</p><p> digitalWrite(redLED, LOW);</p><p> displayCodeEntryScreen();</p><p> }</p><p> void unlockDoor()</p><p> {</p><p> digitalWrite(greenLED, HIGH);</p><p> clearScreen();</p><p> lcd.setCursor(0,0);</p><p> lcd.print(&quot;***************&quot;);</p><p> lcd.setCursor(0,1);</p><p> lcd.print(&quot;** ACCESS GRANTED! **&quot;);</p><p> lcd.setCursor(0,2);</p><p> lcd.print(&quot;** WELCOME **&quot;);</p><p> lcd.setCursor(0,3);</p><p> lcd.print(&quot;***************&quot;);</p><p> //add any code to unlock the door here</p><p> delay(5000);</p><p> digitalWrite(greenLED, LOW);</p><p> displaCodeEntryScreen();</p><p> }</p><p> void displayCodeEntryScreen()</p><p> {</p><p> clearScreen();</p><p> lcd.setCursor(0,0);</p><p> lcd.print(&quot;Let's Make It Secret&quot;);</p><p> lcd.setCursor(0,1);</p><p> lcd.print(&quot;Code Project...&quot;);</p><p> lcd.setCursor(0,2);</p><p> lcd.print(&quot;Enter Secret Code:&quot;);</p><p> }</p><p> void clearScreen()</p><p> {</p><p> lcd.setCursor(0,0);</p><p> lcd.print(&quot; &quot;);</p><p> lcd.setCursor(0,1);</p><p> lcd.print(&quot; &quot;);</p><p> lcd.setCursor(0,2);</p><p> lcd.print(&quot; &quot;);</p><p> lcd.setCursor(0,3);</p><p> lcd.print(&quot; &quot;);</p><p> }</p><p>}</p>
<p>Did you try to indent your code?</p>
<p>i have problem with this error.. can you help me!! </p>
<p>Hi, </p><p>Can i get the Schematic Diagram of this project please ? as i am new to this arduino seystems... Thanks!!1!1!</p>
<p>hi..can i use a tack switches instead of a keypad as an improvised keypad for the password?</p>
<p>Can you help me to do this as a user defined or changeable password lock...</p>
<p>Easy way to Add arduino Library in to Proteus <br><a href="http://www.electronicslovers.com/2015/03/how-to-add-arduino-library-in-to.html" rel="nofollow">http://www.electronicslovers.com/2015/03/how-to-ad...</a></p>
<p>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</p>
<p>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</p>
<p>Hi ,my fellow friends </p><p> I want u all to inform that u can use a 10 K ohm variable resistor instead of key pad.</p><p>u can asign a variable for the mapped value of the variable resistor. For example -</p><p>int x = analogRead ( 1 );</p><p>x = map(x, 0, 1023, 0, 28);</p><p>this is for A-Z letter map down. We can use if and else or if statements for value of each map. For example-</p><p>if ( x = 0 )</p><p>{</p><p> lcd.print ( A);</p><p>}</p><p>this will make it support Arduino uno.</p><p>note : I am a student of class 7 who is very interested in semiconductor ,ic,</p><p>and electronics engineering. if mistakes are any pls write it to me. I am from India.</p>
<p>Nc instructions!!</p><p>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.. </p><p>they have only 3 trials in the password.. then it will send.. </p><p>so bad english.. &gt;_&lt;</p>
<p>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</p>
<p>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.</p><p></p>
Have you tried adjusting the potentiometer?
<p>Hello , </p><p>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 ? :(<br><br> 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 </p><p>Thanks in advance :)</p>
<p>What if i add a servo that will open if the password is valid..what will be the overall coding..btw nc tutorial!!</p>
<p>i used arduino uno with this code it need a litlle bit of more work but here you go</p><p>#include &lt;Password.h&gt;</p><p>#include &lt;Keypad.h&gt;</p><p>#include &lt;LiquidCrystal_I2C.h&gt;</p><p>#include &lt;Wire.h&gt;</p><p>#include &lt;Servo.h&gt;</p><p>Servo myservo;</p><p>int pos = 0;</p><p>Password password = Password( &quot;1234&quot; ); </p><p>LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);</p><p>const byte ROWS = 4; </p><p>const byte COLS = 4; </p><p>char keys[ROWS][COLS] = {</p><p> {'1','2','3','A'},</p><p> {'4','5','6','B'},</p><p> {'7','8','9','C'},</p><p> {'*','0','#','D'}</p><p>};</p><p>byte rowPins[ROWS] = {11, 10, 8, 7};</p><p>byte colPins[COLS] = {6, 5, 4, 3};</p><p>Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );</p><p>void setup()</p><p>{</p><p>myservo.attach(9);</p><p>lcd.begin(16, 2);</p><p>lcd.print(&quot; Enter Password&quot;);</p><p>Serial.begin(9600);</p><p>keypad.addEventListener(keypadEvent); </p><p>keypad.setDebounceTime(250);</p><p>}</p><p>void loop()</p><p>{</p><p>lcd.setCursor(0, 1);</p><p>keypad.getKey();</p><p>}</p><p>void keypadEvent(KeypadEvent keyPress)</p><p>{</p><p>switch (keypad.getState())</p><p>{</p><p>case PRESSED:</p><p>lcd.print(keyPress); </p><p>switch (keyPress)</p><p>{</p><p>case '#':</p><p>checkPassword();</p><p>break;</p><p>case '*':</p><p>password.reset();</p><p>lcd.clear();</p><p>lcd.setCursor(0,0);</p><p>lcd.print(&quot; Enter Password&quot;);</p><p>break;</p><p>case 'A':</p><p>lcd.clear();</p><p>lcd.setCursor(0,0);</p><p>lcd.print(&quot;LASER:ON&quot;);</p><p>delay(2000);</p><p>lcd.clear();</p><p>lcd.setCursor(0,0);</p><p>lcd.print(&quot; Enter Password&quot;);</p><p>break;</p><p>case 'B':</p><p>lcd.clear();</p><p>lcd.setCursor(0,0);</p><p>lcd.print(&quot;LASER:OFF&quot;);</p><p>delay(2000);</p><p>lcd.clear();</p><p>lcd.setCursor(0,0);</p><p>lcd.print(&quot; Enter Password&quot;);</p><p>break;</p><p>case 'C':</p><p>lcd.clear();</p><p>lcd.setCursor(0,0);</p><p>lcd.print(&quot;LOCKDOWN&quot;);</p><p>delay(2000);</p><p>for(pos = 180; pos&gt;=0; pos-=1) </p><p>{</p><p>myservo.write(pos); </p><p>delay(3);</p><p>} </p><p>lcd.clear();</p><p>lcd.setCursor(0,0);</p><p>lcd.print(&quot; Enter Password&quot;);</p><p>break;</p><p>default:</p><p>password.append(keyPress);</p><p>}</p><p>}</p><p>}</p><p>void checkPassword(){</p><p>if (password.evaluate()) </p><p>{</p><p>lcd.clear();</p><p>lcd.setCursor(0,0);</p><p>lcd.print(&quot;*****ACCESS*****&quot;);</p><p>lcd.setCursor(0,1);</p><p>lcd.print(&quot;*****GRANTED****&quot;);</p><p>password.reset();</p><p>delay(100);</p><p>for(pos = 0; pos &lt; 180; pos += 1) </p><p>{ </p><p>myservo.write(pos); </p><p>delay(3); </p><p>}</p><p>delay(2000);</p><p>password.reset();</p><p>lcd.clear();</p><p>lcd.setCursor(0,0);</p><p>lcd.print(&quot; Enter Password&quot;);</p><p>}</p><p>else</p><p>{ </p><p>lcd.setCursor(0,0);</p><p>lcd.print(&quot;*****ACCESS*****&quot;);</p><p>lcd.setCursor(0,1);</p><p>lcd.print(&quot;*****DENIED*****&quot;); </p><p>delay(10);</p><p>password.reset();</p><p>delay(2000);</p><p>lcd.clear();</p><p>lcd.setCursor(0,0);</p><p>lcd.print(&quot; Enter Password&quot;);</p><p>}</p><p>}</p>
<p>the code is not working for me i press upload and it said that &quot;const byte COLS = 3; // Three columns&quot; was declared void need help</p>
sorry..but i cant open the link given <br>all of it
Hello razvan, you did an excellent job with this project.Thank you for sharing! Could you tell me something? <br> 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? <br>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? <br>Thanks !
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). <br>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). <br>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). <br>I was expecting your help and I will be very thankful to you.
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 ? <br>Thanks in advance
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 :( <br>I hope you can help me! <br> <br>Mark
Hi again, i'm getting this error when i started the program for the second time :( <br>I only extracted the password.h &amp; keypad.h to Arduino/libraries. <br>Can you help me? <br> <br> <br>sketch_mar13a:1: error: variable or field 'keypadEvent' declared void <br>sketch_mar13a:1: error: 'KeypadEvent' was not declared in this scope <br>sketch_mar13a:4: error: 'Password' does not name a type <br>sketch_mar13a:21: error: 'Keypad' does not name a type <br>sketch_mar13a.cpp: In function 'void setup()': <br>sketch_mar13a:30: error: 'keypad' was not declared in this scope <br>sketch_mar13a:30: error: 'keypadEvent' was not declared in this scope <br>sketch_mar13a.cpp: In function 'void loop()': <br>sketch_mar13a:35: error: 'keypad' was not declared in this scope <br>sketch_mar13a.cpp: At global scope: <br>sketch_mar13a:43: error: variable or field 'keypadEvent' declared void <br>sketch_mar13a:43: error: 'KeypadEvent' was not declared in this scope <br>
Hello again. <br>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. <br> <br>What the Arduino is telling you in that error message is: &quot;What keypad?! There's a keypad on me?! I don't know how to do that.&quot;. <br> <br>Let me know if that works for you. <br> <br>Cheers!
Thats just the problem.. all the files are there :O <br>So im a bit confused &gt;.&lt;
Including keypad.h and keypad.c ?
Yes, keypad.h &amp; keypad which is a CCP file
i mean CPP
Hmmm. Could you paste in your code?
#include <br>#include <br>#include <br>LiquidCrystal lcd(2,3,4,9,10,11,12); <br>Password password = Password( &quot;4321&quot; ); <br>const byte ROWS = 4; // Four rows <br>const byte COLS = 3; // Three columns <br>// Define the Keymap <br>char keys[ROWS][COLS] = { <br> {'1','2','3',}, <br> {'4','5','6',}, <br> {'7','8','9',}, <br> {'*','0',' ',} <br>}; <br>// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins. <br>byte rowPins[ROWS] = {25, 24, 23, 22}; //connect to the row pinouts of the keypad <br>byte colPins[COLS] = {28, 27, 26}; //connect to the column pinouts of the keypad <br>const int buttonPin = 7; <br>int buttonState = 0; <br> <br>// Create the Keypad <br>Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); <br> <br>#define ledPin 13 <br> <br>void setup(){ <br> pinMode(buttonPin, INPUT); <br> lcd.begin(16, 2); <br> digitalWrite(ledPin, LOW); // sets the LED on <br> Serial.begin(9600); <br> keypad.addEventListener(keypadEvent); //add an event listener for this keypad <br> keypad.setDebounceTime(250); <br>} <br> <br>void loop(){ <br> keypad.getKey(); <br> buttonState = digitalRead(buttonPin); <br> if (buttonState == HIGH) { <br> lcd.clear(); <br>} <br>} <br> <br>//take care of some special events <br>void keypadEvent(KeypadEvent eKey){ <br> switch (keypad.getState()){ <br> case PRESSED: <br> lcd.print(eKey); <br> switch (eKey){ <br> case ' ': guessPassword(); break; <br> default: <br> password.append(eKey); <br> } <br>}} <br> <br>void guessPassword(){ <br> if (password.evaluate()){ <br> digitalWrite(ledPin,HIGH); //activates garaged door relay <br> delay(500); <br> digitalWrite(ledPin,LOW); //turns off door relay after .5 sec <br> lcd.print(&quot;VALID PASSWORD &quot;); // <br> password.reset(); //resets password after correct entry <br> delay(600); <br> lcd.print(&quot;Welcome, Razvan&quot;); <br> delay(2000); <br> lcd.clear(); <br> } <br> <br> <br> else{ <br> digitalWrite(ledPin,LOW); <br> lcd.print(&quot;INVALID PASSWORD &quot;); <br> password.reset(); //resets password after INCORRECT entry <br> delay(600); <br> lcd.clear(); <br> } <br>} <br> <br>
This is AWESOME!!! After i figured out my keypad, it worked just fine! <br>Thank you very much :D
Hey! I'm glad you got it working and that you liked it. <br>Thank's for checking it out. <br> <br>Cheers!
Did you buy the lcd screen at sparfun and if so, witch one is it?
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. <br>If you want to buy one from Sparkfun, I would recommend something like this:<br>https://www.sparkfun.com/products/10862
I see you use alot &rdquo;liquidcrystal&rdquo; 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)
that's just the display type...

About This Instructable




More by razvan_iycdi:Home Speaker Detector DIY 9V Battery Clip Build your own hovercraft 
Add instructable to: