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:

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 #include

Servo 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.

Step 5: Mount in In a Desk or Closet

  1. Make a drawing of how you want to do it
  2. Choose a place on your desk (i suggest above your desk closet)
  3. Draw the cut lines on your desk.
  4. Drill a hole in each corner (watch out!! the hole must be within the marked shape
  5. Put the jig saw in one of the holes and start sawing out the marked shape
  6. (The holes you drilled make it easier to turn the jig saw in the corners)
  7. Saw out a piece of wood (max. 2.5mm thickness) similar to the gap you just awed out your desk
  8. Mark the cut lines for the keypad and keyboard and leds
  9. Cut out the shapes with a fretsaw: drill a hole first and put your fretsaw through it.
  10. Solder jumper wires on the LCD, keypad and LEDS
  11. Put the LCD, keypad and LEDS in the piece of wood
  12. Put the piece of wood in the gap in your desk.
  13. 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

Comments

author
RohanS42 (author)2016-03-04

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

author
siddhant shah (author)RohanS422017-02-01

Actually 4.7k to 7k would be better

author
siddhant shah (author)RohanS422017-02-01

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

author
AhmadA269 made it! (author)2017-01-07

i have this problem while uploading code in Arduino mega please tell me how can i fix this please please

Capture.JPG
author
Rosas25 (author)2016-01-06

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

author
Haris009 (author)Rosas252016-07-23

hi rosas

what kind of project you want to learn

author
Tom De prins (author)Rosas252016-01-10

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

author
Rosas25 (author)Tom De prins2016-01-10

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

author
Tom De prins (author)Rosas252016-01-10

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

author
vincentp3 (author)2015-11-15

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 !!!
author
Tom De prins (author)vincentp32015-11-15

I will try to upload the library's as soon as possible. :)

author
vincentp3 (author)Tom De prins2015-11-16

thanks !!!

author
Tom De prins (author)vincentp32015-11-16

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

author
vincentp3 (author)Tom De prins2015-11-17

but the display shows just white square

author
Tom De prins (author)vincentp32015-11-17

Did you connect everything exact like in the picture? If so you have an adjustable resistor connected. (The small thing you can turn around) If you turn this around you will see the contrast of the letters will change.

If this not helps i will be delighted to help you further. :)

author
vincentp3 (author)Tom De prins2015-11-18

no, the variable resistor is connected, I turn her, nothing happens!

Help !!!

a photo, Perhaps ?

author
Tom De prins (author)vincentp32015-11-18

Yes, that would help.

author
vincentp3 (author)Tom De prins2015-11-19

voila !!!


IMG_0632.JPG
author
Tom De prins (author)vincentp32015-11-19

I can't tell you the problem from seeing this photo. Can you please upload a photo or a video of all the connections?

So far i think you don't have the numbers right in the code.
Please try to connect everything as in the picture and download the .ino file. (The code in the box won't include the libraries)

The connections of the display are (Display --> Arduino):
VSS --> GND
VDD --> +5V
V0 --> (Adjustable resistor)
RS --> Pin 13
RW --> GND
E --> Pin 12
D3 --> Pin 11
D4 --> Pin 10
D5 --> Pin 9
D6 --> Pin 8
D7 --> Pin 7
A (Anode) --> +5V
K (Kathode) --> GND

author
vincentp3 (author)Tom De prins2015-11-20

j'ai tout vérifié les branchements, télécharger le fichier .ino mais cela n'arrange pas mon problème

author
Tom De prins (author)vincentp32015-11-20

Can you please measure the resistance of your adjustable resistor?
You must have an adjustable resistor with a value from around 4,7K Ohms.

If your resistor value is less than 3K Ohms than replace it. :)

author
vincentp3 (author)Tom De prins2015-11-21

4.8 Koms

author
Tom De prins (author)vincentp32015-11-22

Can you try to connect different resitors? If it still doesn't work check this site: http://www.raviyp.com/embedded/141-16x2-lcd-display-not-working-reasons

author
vincentp3 (author)Tom De prins2015-11-23

4.99 V

mon lcd fonctionne très bien !!!

author
Tom De prins (author)vincentp32015-11-23

Can you please answer in English? I understand quiet much in French but i don't understand everything! :p

So are you saying your problem is solved?

author
Tom De prins (author)vincentp32015-11-22

Also check the voltage on your power pins and on the Enable pin (of the display). This must be 5V.

author
Cplusman (author)2015-11-15

It would be a lot better if you could design and demonstrate a locking system (and the thing it is supposed to keep safe) that couldn't be defeated in a few seconds with the right screwdrivers.

author
Tom De prins (author)Cplusman2015-11-15

Don't be so serious! This is just an arduino project. If you really want maximum security you should buy a vault. This is more for fun and education. And even if i make ik stronger there will always be a way to get it open...because it made of wood. Burglars can kick their feet trough the door and they're in. But i don't care. If i really want to save my high value things i will buy a vault. My bedroom is not a bank. Thanks.

author
wkatchi (author)Tom De prins2015-11-20

well you should learn to appreciate others

author
Tom De prins (author)wkatchi2015-11-20

By the way: if you look at the other answers i commented to the other people you can see i'm actually very polite. So maybe you have to learn not to judge people by only 1 comment!

author
Tom De prins (author)wkatchi2015-11-20

I appreciate others but not the comments they sometimes make. And i was being kind in my comment so if don't understand it in the kind way i'm sorry. A little sarcasm doesn't mean i don't appreciate others.

author
KD Techniques (author)2015-11-19

hope to make something like this...

author

Just go for it! :p

author
dshavr (author)2015-11-17

looks nice, indeed i would use a smaller arduino board and a smaller power supply, 220v - 5v (USB) mobile charger maybe?

author
Tom De prins (author)dshavr2015-11-17

I use a 12V adapter. And it works just fine. :)

author
pacman67 (author)2015-11-16

nice but what about changing password without reloading the code ?

author
Tom De prins (author)pacman672015-11-16

I also thought about that. Maybe i will try it out this week. :)

author
mattcintosh (author)2015-11-16

I'm actually trying to get rid of a bunch of similar keypads and LCD screens. If anyone wants a bunch of them, I can give a steep discount

http://www.ebay.com/itm/Data-Vision-16236-SNRLY-2x...

http://www.ebay.com/itm/QTY-2-ACT-Components-16-Key-PinPad-Keypad-Keyboard-2x8-Layout-/231697601118

author
g4ipz (author)2015-11-15

You could run this on the Uno with a display if you replace the LCD with an I2C version and direct all the display routines to that as that would free up the required data pins.

author
Tom De prins (author)g4ipz2015-11-15

Looks like it's difficult. (searched google for I2C arduino) But i'm definetly gonna learn how to do it. Another easier way to safe pins and be able to make the project is connecting all the keypad buttons to an analog input using threshold. I already explained this and put a link of the explaination in another comment. Maybe you can look at it? :)

author
g4ipz (author)Tom De prins2015-11-16

Thanks for the reply. I2C is not difficult (check on the Arduino.cc forum and website) . Once you start using I2C displays you'll never go back to parallel types. :-)


author
Tom De prins (author)g4ipz2015-11-16

Maybe bit it's still an extra cost.

author
ibenkos (author)2015-11-12

Awesome project! I made just the same thing but without a LCD because my Arduino UNO doesn't have enough pins for it. Thanks for shearing :)

author
Tom De prins (author)ibenkos2015-11-12

This is something you can solve by connecting the buttons of the keypad to the analog input. I didn't try it myself yet but i will try it in the future. I found this link which is very interesting: http://tronixstuff.com/2011/01/11/tutorial-using-analog-input-for-multiple-buttons/

author
GianlucaG1 (author)Tom De prins2015-11-14

Yes. You can use analog inputs as digital inputs, like or other I/Os, but you could also connect 4 resistors to the 4 outputs of the keypad and a resistor to ground, then reading by an analog input: the row will be defined by the scanning and the column by the voltage or vice versa.

author
ibenkos (author)Tom De prins2015-11-12

Oh thats smart, maby I'll try it out.

author
vandenbrande (author)2015-11-12

Nice im gonna build it inside a small cash vault those grey regular metal ones that you can wear.

About This Instructable

34,587views

473favorites

License:

More by Tom De prins:Desktop LED lightingArduino password lockKeyboard holder for computer
Add instructable to: