Introduction: Arduino Password Lock
In this instructable i will show you my arduino password lock i made a year ago. And i will teach you how to make your own. I didn't use instructables yet back then so this will be an instructable which has only photo's from the finished project.
Step 1: Parts Needed
Parts:
- Arduino Mega 2560 €8
- Dupont jumper wire €0,69
- 16x2 lcd display €1,5
- Adjustable resistor €1,01/10pcs
- Keypad €3,86 (i used this one)
- Keypad €0,68 (but this one is cheaper)
- 2 leds: green and red
- Piece of MDF
- Breadboard
- Servo
Step 2: Check the Keypad
You can connect it as in the picture but i recommend you check it with a multi meter.
Step 3: The Code
I got this code from someone else. I don't remenber his name or where i got it so credits to the anonymous guy. Altough i put some major changes in the code so i just used the base of the code from this guy.
Before you copy the code and start uploading implement the correct libary's in your library folder in the arduino map. You can find this as following: Windows C: --> program files (x86) --> Arduino.
Anyway, here's the code (but you better download the file):
#include
#include #include #includeServo myservo;
//constants for LEDs int greenLED = 22; int redLED = 23;
LiquidCrystal lcd(13, 12, 11, 10, 9, 8, 7); Password password = Password( "4155" ); int currentPosition = 0; const byte ROWS = 4; // Four rows const byte COLS = 4; // Four columns // Define the Keymap char keys[ROWS][COLS] = { { '1','2','3','A', } , { '4','5','6','B', } , { '7','8','9','C', } , { '*','0','#','D', } }; // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins. byte rowPins[ROWS] = { 47, 46, 45, 44}; //connect to the row pinouts of the keypad byte colPins[COLS] = { 51, 50, 49, 48}; //connect to the column pinouts of the keypad
// Create the Keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){ lcd.begin(16, 2); Serial.begin(9600); keypad.setDebounceTime(50); displayCodeEntryScreen(); keypad.addEventListener(keypadEvent); //add an event listener for this keypad myservo.attach(2); myservo.write(180); //setup and turn off both LEDs pinMode(redLED, OUTPUT); pinMode(greenLED, OUTPUT); digitalWrite(redLED, LOW); digitalWrite(greenLED, LOW); }
void displayCodeEntryScreen() { password.reset(); lcd.clear(); lcd.setCursor(2, 0); lcd.print("Enter Code:"); lcd.setCursor(0,1); keypad.addEventListener(keypadEvent); //add an event listener for this keypad //setup and turn off both LEDs pinMode(redLED, OUTPUT); pinMode(greenLED, OUTPUT); digitalWrite(redLED, LOW); digitalWrite(greenLED, LOW); }
void loop(){ keypad.getKey(); }
//take care of some special events void keypadEvent(KeypadEvent eKey){ switch (keypad.getState()){ case PRESSED: lcd.print(eKey); switch (eKey){ case '#': checkPassword(); break; case '*': displayCodeEntryScreen(); break; default: password.append(eKey); } switch (keypad.getState()){ case PRESSED: switch (eKey){ case 'D': myservo.write(180); displayCodeEntryScreen(); } } } }
void checkPassword(){ if (password.evaluate()){ digitalWrite(greenLED, HIGH); lcd.clear(); delay(30); lcd.setCursor(1, 0); lcd.print("Acces Granted"); lcd.setCursor(4, 1); lcd.print("Welcome"); unlockdoor(); delay(2500); displayCodeEntryScreen(); } else{ loop(); { redlight(); } lcd.clear(); delay(10); lcd.setCursor(2, 0); lcd.print("Acces Denied"); delay(2500); lcd.clear(); displayCodeEntryScreen(); } }
void unlockdoor(){ //controls servo that locks the door myservo.write(90); digitalWrite(greenLED, HIGH); delay(5000); }
void redlight(){ digitalWrite(redLED, HIGH); delay(100); digitalWrite(redLED, LOW); delay(100); digitalWrite(redLED, HIGH); delay(100); digitalWrite(redLED, LOW); delay(100); digitalWrite(redLED, HIGH); delay(100); digitalWrite(redLED, LOW); delay(100); digitalWrite(redLED, HIGH); delay(100); digitalWrite(redLED, LOW); delay(100); digitalWrite(redLED, HIGH); delay(100); digitalWrite(redLED, LOW); delay(100); digitalWrite(redLED, HIGH); delay(100); digitalWrite(redLED, LOW); delay(100); digitalWrite(redLED, HIGH); delay(100); digitalWrite(redLED, LOW); delay(100); digitalWrite(redLED, HIGH); delay(100); }
Step 4: Connect and Put It in a Box
Connect all the parts like in the picture and put it in a box.
I didn't put it in a box but this is something i will do in the future because if you don't do it, it gets really messy.
If you want to mount the keyboard and display and leds in or on a desk or closet jsut put the arduino and the breadboard it the box.
Attachments
Step 5: Mount in In a Desk or Closet
- Make a drawing of how you want to do it
- Choose a place on your desk (i suggest above your desk closet)
- Draw the cut lines on your desk.
- Drill a hole in each corner (watch out!! the hole must be within the marked shape
- Put the jig saw in one of the holes and start sawing out the marked shape
- (The holes you drilled make it easier to turn the jig saw in the corners)
- Saw out a piece of wood (max. 2.5mm thickness) similar to the gap you just awed out your desk
- Mark the cut lines for the keypad and keyboard and leds
- Cut out the shapes with a fretsaw: drill a hole first and put your fretsaw through it.
- Solder jumper wires on the LCD, keypad and LEDS
- Put the LCD, keypad and LEDS in the piece of wood
- Put the piece of wood in the gap in your desk.
- You can mount this piece of wood with small corner profiles or with glue (i recommend the first one)
Optional:
If you mount the piece of wood a little deeper the the surface of the desk you can add a cover for your electronics. You can simply do this with a piece of MDF (2.5mm) which is slightly bigger than the gap in your desk. And with a small hinge
Step 6: Mount the Locking System
This was the hardest part so i'm sorry if i didn't explain it clearly.
Get a piece of metal (aluminum) and divide it in 3 parts. 2cm for the middle part is enough. (1cm is better)
3cm for the other parts is also enough. Drill two holes in 1 of the 3cm parts. Thereafter fold the piece in a U-shape.
Drill two holes in your closet door at the same distance as the holes in the metal.
Drill this two holes in the middle of the door (not like i did on the photo) unless you use 2 servos (this is better for large doors)
Mount the U-shape on the door with two rivets.
Now for the servo just look at the photo's. Mount the servo 2cm (or 1cm, depends on your middle part of the U-shape) from the door.
I did this with super glue but i recommend to do it a different way.
Step 7: Put a Switch on the Power Supply
A couple month's ago i replaced the laptop 12V power supply with a power supply from an old pc.
I connected a light switch to the start wires of the power supply and on the 12V output to the arduino. So now i can switch on the power supply and the password lock.
I use this power supply for different things: 2 led strips, leds in my closet, and the lock.
The power switch wires of the power supply are green and black. If you connect this 2 wires and the power supply is connected it will start working).
Step 8: Conclusion
I really enjoyed making this. This was my first project i wrote arduino code myself and i learned pretty much.
Ther's just one thing: i should've thought better about how to cut out the square in my desk because i didn't do it very nice.
Some improvements i want to do:
- Change the arduino mega 2560 to the arduino uno and connecting all the buttons of the keypad to the analog input (using threshold)
- Putting the board in a box
- 3D printing a new cover which covers the ugly gap (see photo's and video). I will do this as soon as my self made 3D printer works. (Don't work yet cause of the nozzle which keeps clogging and the filament that keeps curling) (As soon as it works there will be an instructable of it too)
- Use a solenoid instead of a servo
So dear DIY'ers
If you have tips for me conform this project or even on how i make my instructables, just say it!
I love to hear it from you guy's so i can learn from it.
(English classes is not a good tip!) :p
Please vote for my project on top of this page!! THANKS!! :D
Step 9: Video's

Participated in the
Tech Contest
53 Comments
5 years ago
Hi, I like your idea but my question is, can I use the arduino uno instead of arduino mega?
Reply 3 years ago
Hi, I made it on my arduino Uno R3, the code is:
#include <Password.h>
// #include <SoftwareServo.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
//Servo myservo;
//constants for LEDs
int greenLED = 4;
int redLED = 5`;
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
Password password = Password( "4155" );
int currentPosition = 0;
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
// Define the Keymap
char keys[ROWS][COLS] = {
{
'1','2','3','A', }
,
{
'4','5','6','B', }
,
{
'7','8','9','C', }
,
{
'*','0','#','D', }
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {
0, 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
4, 5, 6, 7}; //connect to the column pinouts of the keypad
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
lcd.begin(16, 2);
// Serial.begin(9600);
keypad.setDebounceTime(50);
displayCodeEntryScreen();
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
// myservo.attach(2);
// myservo.write(180);
//setup and turn off both LEDs
//pinMode(redLED, OUTPUT);
//pinMode(greenLED, OUTPUT);
analogWrite(redLED, 0);
analogWrite(greenLED, 0);
}
void displayCodeEntryScreen()
{
password.reset();
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Enter Code:");
lcd.setCursor(0,1);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
//setup and turn off both LEDs
//pinMode(redLED, OUTPUT);
//pinMode(greenLED, OUTPUT);
analogWrite(redLED, 0);
analogWrite(greenLED, 0);
}
void loop(){
keypad.getKey();
}
//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
lcd.print(eKey);
switch (eKey){
case '#':
checkPassword();
break;
case '*':
displayCodeEntryScreen(); break;
default:
password.append(eKey);
}
switch (keypad.getState()){
case PRESSED:
switch (eKey){
// case 'D': myservo.write(180); displayCodeEntryScreen();
}
}
}
}
void checkPassword(){
if (password.evaluate()){
analogWrite(greenLED, HIGH);
lcd.clear();
delay(30);
lcd.setCursor(1, 0);
lcd.print("Acces Granted");
lcd.setCursor(4, 1);
lcd.print("Welcome");
unlockdoor();
delay(2500);
displayCodeEntryScreen();
}
else{
loop(); {
redlight();
}
lcd.clear();
delay(10);
lcd.setCursor(2, 0);
lcd.print("Acces Denied");
delay(2500);
lcd.clear();
displayCodeEntryScreen();
}
}
void unlockdoor(){ //controls servo that locks the door
// myservo.write(90);
analogWrite(greenLED, HIGH);
delay(5000);
}
void redlight(){
analogWrite(redLED, HIGH);
delay(100);
analogWrite(redLED, LOW);
delay(100);
analogWrite(redLED,255);
delay(100);
analogWrite(redLED, LOW);
delay(100);
analogWrite(redLED,255);
delay(100);
analogWrite(redLED,0);
delay(100);
analogWrite(redLED,255);
delay(100);
analogWrite(redLED,0);
delay(100);
analogWrite(redLED,255);
delay(100);
analogWrite(redLED,0);
delay(100);
analogWrite(redLED,255);
delay(100);
analogWrite(redLED,0);
delay(100);
analogWrite(redLED,255);
delay(100);
analogWrite(redLED,0);
delay(100);
analogWrite(redLED,255);
delay(100);
}
Reply 4 years ago
You can but you'll need a whole different setup and code. You'll need to connect it to an analog input and use resistors. Check this vid: https://www.youtube.com/watch?v=W8ZSeLD90KA.
With the code i used and shared here it's not possible cause there are not enough digital pins on an uno.
3 years ago
C:\Arduino\bem_program1\bem_program1.ino:5:39: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
Password password = Password ( "9534" );
Plsss help the program wont run even without errors
Question 5 years ago
Is there something new we have to add toward the code if LCD display is not working because all mine does is turn on but shows nothing on the display. Any explanations on why this is happening?
Answer 4 years ago
I had the same problem and it was a bad pot. Short the center tap to ground and see if you get any display. If so it was the pot, replace it.
5 years ago
so i can make that
and real it also work on doors because all those wires
7 years ago
Hello sir,
Actually I am in class 8 ,so this this stuff of kind of new to me, Please guide me through in an easier language.I am really surprised by your creations,I am also your big fan.i have ordered all the required material but i did not get an adjustable resister,so please help me by telling that is it really necessary ,and if it is ,then what can i replace it with ? (please reply fast)
Thanks :D
Reply 6 years ago
Actually 4.7k to 7k would be better
Reply 6 years ago
Hi rohan adjustable resistors is juat for asjusting the contrast of the lcd
If u cant get one put a simple resistor varying from 1k to 2k
7 years ago
Hi Sir! I'm a student and I, together with my groupmates proposed a project which is a door alarm with a password, and obviously, as much as possible, with the use of arduino in connection with our course; embedded systems. Can you pls help me and explain this to me? Thankyou :*
Reply 6 years ago
hi rosas
what kind of project you want to learn
Reply 7 years ago
Hi,
I'm sorry it took so long to answer.
I don't quiet understand what you mean with our course; embedded systems. I'm still a student too when it comes to arduino and other systems. But if you explain to me what you mean i will try to explain all i know about it. :)
Reply 7 years ago
It's okay. What I am trying to say is that I need to do a project which is a door lock requiring a password using an arduino, can you help me with this one? Btw, thankyou for paying attention. You do great :)
Reply 7 years ago
Hi,
i would love to help you but i think everything is explained in the instructable. If you have questions about a specific item you can always ask them off course. :)
7 years ago
i haven't got library "Password.h"
please it is possible to have this one ???
thank you !
"Password_lock3.ino:1:22: fatal error: Password.h: No such file or directory
compilation terminated.
Erreur lors de la compilation."
PS: I'm French !!!Reply 7 years ago
I will try to upload the library's as soon as possible. :)
Reply 7 years ago
thanks !!!
Reply 7 years ago
I uploaded the files in step 3 ("the code").
Ps: if you really like this project. Please vote for this project on top if this page. Thanks! :D
Reply 7 years ago
but the display shows just white square