Introduction: Arduino Combination Door Lock: Lockduino

Ready to put a combination lock on your door to keep out intruders? You've come to the right place! In this i'ble I will show you step by step how to make a combination lock for your door!

Watch this video of the finished product!

 

What did you make?
Hi, I'm 15, and I made Lockduino! It's a lock that is controlled by 4 potentiometers and a pushbutton. It may also be controlled by IR in the future :?
I just used some perf board, ribbon cable and basic electronics to make it. I got so mad with the perf board (my dremel is very tiny and doesn't cut well) so I brandished my oscillating saw and zzzzzzzip! Whoops! Maybe next time I should be a little more careful ;-).
How did you make it?
Tell us how you got the idea for the project.
We were staying a rental cabin in the mountains for the weekend and I was utterly enthralled by the electronic keypad that you typed in your cabin code to get it. You type in the code and heard, "WRRAANT" and the door popped open. So I decided to make one; modified. Hence I present to you: Lockduino! 
Did you work with anyone else?
Nope. Just me!
Did your plan and ideas change as you worked on the project?

No, not really. I pretty much stuck the same plan the whole time.
Where did you make it?
I made it all in my room on my electronics work table and downstairs by our computer (for programming Arduino).  A lot of running up and down the stairs!
How did the project connect to other activities in your life?
Well, it keeps out my friends when I don't want them in my room, it keeps my stash of equipment safe and sound!
What did you learn?
What I learned was how to properly use if statements with Arduino. It took some time  but I got the hang of it. You can see this thread to see how I was in misunderstanding about how to construct my if statements!


Step 1: Ingredients:

Electronics:
  • Arduino
  • Micro servo
  • Green LED
  • Red LED
  • (2) 350 ohm reistors
  • 10k ohm resistor
  • (4) 10k, 50k, or 100k micro potentiometers (the higher the resistance the better
  • Perf board
  • Momentary pushbutton
  • 2.54 cm. pin headers
  • Insulated jumper wire
  • Heat shrink
  • Ribbon Cable
  • 9v battery and clip
  • 4 AAA battery holder
Tools:
  • Soldering pencil
  • Tool to cut perf board (I found that the oscillating saw works the best!)
  • Razor blade
  • Wire cutters
  • Wire strippers
  • Needle-nose pliers
  • Electrical tape
  • Helping hands are helpful!
  • Hot glue gun
  • Heat gun
  • Sharpie
  • Paper and pencil
  • Drill with 1/4  bit, and 3/8 bit.
Parts:
  • Insulated ring terminal
  • Basswood or 1/4 ply
  • Double-sided tape

Important Terms:

  • Block - Any code in between two brackets; for eg. { code here } 'code here' is "in the block."

Step 2: Prepping the Perf

How many times have I said prepping the perf? 
Anyways we're going to get started my drawing out a little template for the 2 LEDs (or one if you have RGB LED) and for the pots. I spaced the pots about 1 1/2 inches apart. Just keep in mind that you have to leave enough room for your turning knob. Cut out your template and solder all the components to it.
To connect all the potentiometers; begin by making a jumper like the one shown in picture 7. You don't have to do this, you could just use a insulated wire like I did with the positives. All the negatives (left side) connect together. Connect all the positives (right side).
Now, VERY IMPORTANT! TEST! You don't want to finish the project and then go, OH NO, it's not working!!!
To test, hook up the red wire (from the perf board) to 5v on Arduino and the black to GND. Connect your multimeter's black test lead to GND. Connect the red wire (of the multimeter) to the middle pin of the pots. Turning the pot should give you a read of 0 volts through 5 volts.
EVEN MORE IMPORTANT!
Make sure that when you solder the pots on they are all level and the same height. Otherwise, you will have horrible problems when it comes to adding the knobs.

Step 3: Ribbon Cable Dissection & Soldering

Ribbon cable! My good friend gave me this from I guess his old computer. Whatever the FD drive is! So, using razor blade, separate 8 wires from the rest. Then I used some wire cutters to cut it. Strip the ends of the wires. 

Soldering:

Working with ribbon cables can be tricky, but I found a way to master it. Draw a diagram! You can see in my diagram (the top) where everything should go. The bottom is just everything reversed because when I was soldering I was soldering with it upside down.

Step 4: Arduino Backpack

This is what others call a "shield", but I like 'backpack'. Now what's the purpose of this? It's so that if you need to use your Arduino for something else, you can just pull it off the top of the Arduino. If you want it back on, you can just push it right back onto Arduino!
Now there is a small problem with the pictures. I didn't put the open button on the inside of the door until later, so you won't see it in these pictures. Instead of making a 4 segment pin header make a 5 segment header.The fifth one will go in pin A4.
  1. Lay the perf board on top of the the Arduino. Then stick some pin headers through the perf and into the Arduino's output pins. This is to hold the perf board on the Arduino. Using a sharpie, outline the Arduino on the perf.
  2. Cut the perf
  3. Mark a rectangle in the middle. Use a dremel to cut it out. I was able to cut it about halfway, then knock it out with a screwdriver.
  4. Cut off the pin headers. (1, 2, 2, 5) 
  5. Place all the pin headers into the Arduino pins. (the 4 goes into pins A0-A3, one of the 2 goes into 5v and GND, the other 2 connects to pins 12 and 13, one of the 1 goes in A4, and the other 1 goes into pin 9.)(see pictures)
  6. Put the piece of perf on top of the Arduino, letting the pins slip in the holes.
  7. Put a drop of solder on top of the pins to hold them in. 
  8. Feed the ribbon cable though the rectangle.
  9. Make all the solder connections. Be careful! Don't forget the resistors, pins 12 & 13!
  10. Cut off the connector of the servo and strip the ends.
  11. Attach the battery pack's positive and negative to the positive and negative of the servo. 
  12. Solder the GND of the battery and servo to GND on Arduino.
  13. Solder the control wire of the servo to pin 9.
  14. Flatten out the tabs of a momentary push button.
  15. Clip one of the leads of a 10k resistor off and solder it to the switch.
  16. Solder a wire to the other end of the resistor.
  17. Solder a wire on before the resistor on the same pin.
  18. Solder a red wire on the other pin of the push button.
  19. Cover all the connections with heat shrink.

Step 5: Testing:

Now testing is always a good thing. It always good to know whether your project is working or not! Upload this code and open up serial monitor. See the video. Serial monitor is on the right. Warning: This is not the final sketch! This is just to test the pots!

Step 6: Making the Front Panel

So I just took a piece of basswood and marked off where all the potentiometers where. Then I took a ruler and drew the same marks in the middle. Using a 3/8 drill bit, I cut drilled the holes for the pots. MAKE SURE then pots fit in and are nice and level! For the LEDs just use a 1/4 drill bit as usual. 

When you are putting on the ring terminals, MAKE SURE THAT THE POT IS TURNED ALL THE WAY TO THE LEFT FIRST!

Calibrating-
To do this you need to load the sketch to your Arduino and open up serial monitor. Slowly turn the knob. In serial monitor when it says 1, make your first mark. When it says two, make your second mark etc..
Making a frame-
Using some basswood sticks, I cut them to length and glued them on the edges. See photos.

I attached some double-sided tape to the battery holder, Arduino and the wooden frame.

After yo put the LEDs in sand them down the the height of the holder for some diffusion.

Step 7: Making the Servo Holder

So I'm sure you can use some type of aluminum sheet metal, some type of laser cut acrylic, or 3D printed holder, but I don't have any of those. So I used a metal lid to a game. I was able to use my old pair of scissors to cut it up. BE CAREFUL, THE EDGES ARE SHARP! What I did is kinda hard to explain so just go through the photos one by one. 

Step 8: Final Pictures

Step 9: Breaking Down the Arduino Code

Now the whole point is to learn, right? Now what do we want to happen? See the flowchart above. Let's get started by adding all of the pins.
This is just setting up all the pins. I'm not going to waste any time explaining this.

Setting up the the outputs.

buttonState = digitalRead(button1);
This is setting the words 'buttonState' the the digital reading at pin button1, which is pin A4. Since it's using the digitalRead function 'buttonSate' can either be HIGH or LOW.
int analog1 = analogRead(A0);
This is for taking an analog reading at pins A0. The analog reading is 0-1023.
int pot1 = analog1 * (10.0 / 1023.0);
Convert the analog reading from pin A0 to 0-10 from 0-1023

The rest of the code is for the other analog readings on the others pins A0-A3.
if (pot1 == 4 && pot2 == 5 &&
    pot3 == 3 && pot4 == 6)

Now this is where you need to put you your own combination in. I'm going to make mine 4536. 
This is to test the following: If pot1 is equal to 4, and if pot2 is equal to 5, and if pot3 is equal to 6, and if pot4 is equal to 1, do the following. Change the numbers pot1,2,3,and 4 equal to create your own code. 
 {
   digitalWrite(greenLED, HIGH);
   digitalWrite(redLED, LOW);
   myservo.write(90);
 }


Let's add another if statement

elseif (buttonState == HIGH) Is the digital reading at pin A4 high??? Yes, it is! So do. . .

 {
   digitalWrite(greenLED, HIGH);
   digitalWrite(redLED, LOW);
   myservo.write(90);
   delay(5000);
 }

If either of these if statements aren't true, then do the following:

else  
  {  
      digitalWrite(greenLED, LOW);
      digitalWrite(redLED, HIGH);  
      myservo.write(170);  
 }

Now you may have noticed I added a delay in the button block, but not the pot block. Well the reason why I did this is so that you don't have to hold the button. If you look over the code, you will see that there are no delays, so Arduino is constantly doing the loop over and over and over again at a very fast speed. So the code says, "if the button is high, unlock the door'. Well if you release the button, the loop is looped and it sees the the button is not HIGH, so it locks the door. With the delay, once it detects the button is pushed, it will preform our action (unlocking the door, changing the LEDS), then is wait for 5 seconds before running the loop again. If you don't understand, try it. Take out the delay and see what happens.

Step 10: Final Arduino Sketch

If you can tell the code is 4561. Notice that I change these numbers up a bit from the previous code. Note: You will most likely have to change the servo values. Start off with 90˚ and slowly work your way up and down. You don't want to break your servo! For powering the Arduino I used a USB cable and a USB cell phone charger so I could have my lock constantly running!

Step 11: Conclusion:

I hope you guys enjoyed this i'ble! If you like it, vote it as a winner for the UP contest and the Make-to-learn Contest!
Please post your pictures of yours and if you have any question leave them in the comment box below or PM me.

P.S.
I didn't think about adding the pushbutton until after I had finished the project, so I'm sorry that some of the pictures don't align with the text.


Cheers!

Comments

author
Neel Dhebar made it! (author)2015-05-19

Interesting project with the Arduino but there are several thing I'd like to point out:

Well, lets face it: anyone will just keep turning the knobs until they can get in so you could add a variable to count the number of attempts and then lock out once say, 5 attempts were wrong. With an Arduino of course you could have a smartphone app that wirelessly communicates with the Arduino and sends a text message if anyone enters.

The possibilities are endless.

Keep posting!

author
HavocRC made it! (author)HavocRC2015-05-19

If you'd like to try then have fun breaking in have fun! That's a good idea though! At the time I barely new about electronics so that was all I knew about. I may make a second version. . .

author
electric_guy made it! (author)2014-03-22

can you please help me.. I followed your connections but my LED lights wont light up and my servo is not functioning properly :( I used this for my elective project..

author
HavocRC made it! (author)HavocRC2014-03-24

Did you use a ribbon cable?

author
electric_guy made it! (author)electric_guy2014-03-25

yes I used the ribbon cable.. I passed the project but the LED is still not working but the servo works fine :)

author
HavocRC made it! (author)HavocRC2014-03-26

I'm glad you passed! Well it's very difficult for me to help you because there are a number of things that can be wrong. Try checking these things:

1) LEDs are wired correctly, Cathode (shorter lead) to GND, and the

Anode to the correct pin on the Arduino.

2) In the sketch make sure which pins the LEDs are supposed to be connected to, then trace your LED connections and see if they go back to the correct pin.

3) Nothing is shorting out

4) Bad LEDs

I'm sorry I can't really help you further, as I cannot see your project. Good luck!

author
electric_guy made it! (author)electric_guy2014-03-26

ok.. thanks for the tips :)

author
lovelyjoy767 made it! (author)2014-01-07

Hello! Good day. Can I ask for the schematic diagram of this project (Arduino Combination Door Lock: Lockduino). Can you please send it to my email, lovelyjoy767@gmail.com. Thanks!

author
HavocRC made it! (author)HavocRC2014-01-08

Hey! I just realized that I haven't made a schematic would you please give me a couple of day since I'm busy. I need to make one anyways.

author
ashigaru-sha made it! (author)2013-07-30

I am tired and I didn't read much (and am currently unable to view the comment on this i'ble) so I don't know if you mentioned whether it would be possible to change the code or not... Otherwise, I am 100% impressed by this creation.

author
HavocRC made it! (author)HavocRC2013-10-31

Ok! I clearly gave instructions on how to make the code and change it! Maybe you should have a nice, long rest, then come back after a cup of coffe and read it again :). I hope you can understand it.

author
mweaver8 made it! (author)2013-07-21

i took apart my comuter and found a cable labled "FD" connected to the floppy disc drive

the computer is still working

author
GpaSteve made it! (author)2013-04-24

I have built this, but i get a "error compiling" .
If I remove all the code for the servo it works fine. Any suggestions?

author
9mag9 made it! (author)9mag92013-05-11

Have you installed your Arduino(I think you only need to do this with the Mega 2560 and ADK) correctly? You can do this by (windows) going to device manager and right clicking the unknown device and click update driver software. Then click "browse my computer for software" and browse to the location of your Arduino folder. Once there click on the folder that says drivers(do not expand it). Lastly click open. That should install the drivers. I forgot to install the drivers on my Arduino when I was working with some led and they just did random things.

author
HavocRC made it! (author)HavocRC2013-04-24

GpaSteve, I just think I know what your problem is. You most likely haven't installed the servo library. Is this true?

author
GpaSteve made it! (author)GpaSteve2013-04-24

Servo library is loaded. Will remove and reload and see if that fixes it
Thanks for the response

author
HavocRC made it! (author)HavocRC2013-04-25

I'm not sure what your problem is because that's the code that is running on my Arduino right now. Can you take a screenshot of the error and the highlighted text? Thanks!

And, what is the name of your servo library folder, is it just named 'Servo' or is it something else like 'Servo.h'?

author
GpaSteve made it! (author)GpaSteve2013-04-26

Error message:
Error Compliling
C:\Users\steve\Documents\Arduino\libraries\Servo\Servo.cpp: In member function 'int Servo::readMicroseconds()':
C:\Users\steve\Documents\Arduino\libraries\Servo\Servo.cpp:327: error: 'clockCyclesPerMicrosecond' was not declared in this scope

Folder is servo, servo.h is in this folder.

Thanks for your assistance

Steve

author
HavocRC made it! (author)HavocRC2013-04-26

Steve I honestly have absolutely no idea what is the problem. You will have to ask a forum.
Does Arduino highlight any certain text? Can you post a pic of the highlighted text? Thanks.

author
GpaSteve made it! (author)GpaSteve2013-04-26

No text is highlighted.
Thanks for all your assistance. I will ask around.

author
HavocRC made it! (author)HavocRC2013-04-26

Ok. I'm sorry. I don't think it's the code because it's running on my door as I type.

Good luck.

author
GpaSteve made it! (author)GpaSteve2013-05-03

Not sure what happened but its working now. Thanks again for you help

author
shaddoty made it! (author)2013-04-09

If statements are annoying it took me about a week to figure them out (really annoying)
But I figured it out and it turned out to be a simple syntax error Stupid me

author
HavocRC made it! (author)HavocRC2013-04-09

Yeah were you doing this???

if (this == this) ; {} (adding the semicolon)
instead of this?

if (this == this) {}

Because that's what I do all the time :D

author
Robbiezxc made it! (author)2013-04-02

hi relay liked this you explained the code witch helped me out loads as i am new to arduino and try ting to make a model rocket launcher with a keypad lcd and relay not having must look but think this will help me get some where but i noticed that you disabled the copy on you code would you send me the code so i can try this out thanks

author
HavocRC made it! (author)HavocRC2013-04-02

Hey robbi! I'm really glad I was able to help you! Actually, I did not disable copying. Yes, I know, it shows a circle with a cross, but all you have to do is simply to click, drag and select the text. You can do that or you can click in the gray area and hit ctr-A to select all the text within the box.

Glad you appreciate!

P.S.
Don't forget to give it a vote :D

author
shaddoty made it! (author)2013-04-01

this is genius i want to try this with slider pots to open a secret compartment

author
HavocRC made it! (author)HavocRC2013-04-01

Or you can wait until I make version two that uses a "credit" card- so all you have to have is a thin slit somewhere where you put in the card, then it pops open :D

author
mazingo made it! (author)2013-03-23

Wow, congratulations! That's a smart idea and I bet it was incredibly fun to make.

You've got a great future :)

author
HavocRC made it! (author)HavocRC2013-03-23

Yes I had TONS of fun making it!

Encouragement like yours keeps me going. Thank you very much!

author
Ceralor made it! (author)2013-03-22

|Whatever the FD Drive is!

..I am so old and I'm only 25, holy moly. ;_;

Neat project! But I hope you're joking about the FD Drive comment..?

author
HavocRC made it! (author)HavocRC2013-03-22

No really, I have no idea what a FD drive is! I guess the only thing would be Floppy Disk? Dude, that's old school stuff! I use SD cards, micro SD cards, USB drives, and micro USB drives. Floppy disks, CDs, tapes- I know nothing ;-)

author
jmiddea made it! (author)2013-03-21

Great job, I love your creativity. Be carefull with the power outages when the door is closed with you outside the room ;-)

author
HavocRC made it! (author)HavocRC2013-03-21

Haha yes! Actually my doorknob is very bad, so if I turn the doorknob really, really hard it will come open. You gave me a idea, I should make a backup power supply :D

Thanks!

author
stringstretcher made it! (author)stringstretcher2013-03-22

Why not provide for a "through the door" power supply, so the Arduino is not even turned on until you insert an "electronic key"? That would provide power to the board and servo, and make it even more secure.

author
HavocRC made it! (author)HavocRC2013-03-22

Yeah I could put a DC jack on the side of my wooden frame! That would be cool!
I may do that in one of my future locks- there's more to come. This one was just for play, nothing realistic. I'll make a real one for a safe some time.

author
privatier made it! (author)2013-03-21

Very nice project ...
Please change your name: give yourself a boost for completing such projects.
Get rid of the loser: you are a winner!

author
HavocRC made it! (author)HavocRC2013-03-21

Haha yes I was thinking about changing my name but I have totally no idea what to change it to! Everything already seems taken!

And thanks!

author
welderhero made it! (author)2013-03-21

i really like the idea of "one off" security systems. Having store bought stuff just seems to me that the bad guys get a guide as to how to defeat them. Home made one of a kind could take too long to figure out. One must of course resist the temptation to show everyone "how cool" your locks are. Keeping your home and personal defense abilities and plans a secret is the way to go.

author
HavocRC made it! (author)HavocRC2013-03-21

Yeah, I would never spend all that money on security systems when I could make one for about 1/4 the price (if not less). I have plans for a better lock than this one, using similar concepts, but it's a lot harder to open the just turning four knobs. Like you said, I could tell you, but that would give away my the key to my house :D. I made my i'ble just to give you an idea of how to make one then you can expand of that. Haha, come to think of it, it would be quite senseless to make an i'ble of a lock for your front door :D.

author
Istarian made it! (author)2013-03-21

I think you could make something simpler with reed switches (ones that you can control with a magnet). You just make several rotatable reed switch modules (rotatable for configurable combination), then make a interface outside like you have and attach a magnet to the moving piece so that the magnet is where the number is (in front of or behind the perf board). Then you just need to detect the state of four switches and you're good. With some multiplexing or creative logic gates you could maybe merge into one signal line. You just MAKE a circuit taking in 4 input states that only gives a 1 when they're all on (three AND gates, single quad-gate AND chip).

author
HavocRC made it! (author)HavocRC2013-03-21

Yep Yep, I'm sure you could do something like that!

author
Lindie made it! (author)2013-03-21

Love this! Great idea!

author
HavocRC made it! (author)HavocRC2013-03-21

Glad you enjoyed!

author
mrmerino made it! (author)2013-03-20

If you used full-sized pots, you could have actual knobs.

author
HavocRC made it! (author)HavocRC2013-03-20

Too bad I didn't have any. But yes, that's what I was intending on doing. But I kinda like the ring terminals, I think thy look cool.

author
TobaTobias made it! (author)2013-03-20

Great project, very nice and orginal! Deserves a patch.

author
HavocRC made it! (author)HavocRC2013-03-20

Thanks for the patch!

author
agm88 made it! (author)2013-03-20

nice and very cool

author
HavocRC made it! (author)HavocRC2013-03-20

I'm happy you liked it!

About This Instructable

46,285views

297favorites

License:

Bio: 19 year old hobbyiest and future EE.
More by HavocRC:DIY FPV Antenna Protector CaseControl Your RC Plane With Your Phone's AcclerometerDIY Receiver Controlled Switch (Cheap and Easy)
Add instructable to: