Arduino Password Lock

37,912

478

46

Posted

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

Share

  • i have this problem ...-AhmadA269

    AhmadA269 made it!

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • Sew Warm Contest 2018

    Sew Warm Contest 2018
  • Paper Contest 2018

    Paper Contest 2018
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

48 Comments

Hi, I like your idea but my question is, can I use the arduino uno instead of arduino mega?

so i can make that

and real it also work on doors because all those wires

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

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

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

hi rosas

what kind of project you want to learn

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

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

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