Digital Combination Lock!

57,768

55

44

Published

Introduction: Digital Combination Lock!

 

I've always wondered how did electronic locks work, so once i finished the basic digital electronics course I decided to build one myself. And I´ll help you to build your own!

 

You could connect it to anything from 1v to 400v(or maybe more that depends on the RELAY), DC or AC, so you could use it to control another circuit, or even to electrify a fence!! (please dont try that, really dangerous)… I connected a mini chrismas tree to the output (110v) cause I hadnt taken the holydays decoration off my lab, so it was around at the time i finished the proyect.

 

Here are some pictures of the finished System, and a video too, so you can see it working.

Step 1: How Does It Work?

 
 
First I thought in what was needed to be processed and how. So i drew this diagram as a map to guide me as i build each part of the proyect. Heres a summary of how it works.
  • First we need a circuit to decode the 10 possible inputs (0-9) to its 4 output BCD (Binary Coded Decimal), and another output that tells us when any button is pressed.
  •  Then we need to build the circuit for our two 7-segments displays to work properly, with 4 inputs for a BCD number and of course 7 outs for our displays, ( I used the IC 74LS47)
  • Then a circuit to save each pressed number and toggle between displays
  • As well as an internal memory for our password
  • And, the hearth of our lock, the comparator (its 8 bits ´cause there are 4 bits per digit in the display, meaning that if you want to do a 4 digit lock you will need two of this connected together.) This will tell us if the numbers in the displays are the same as the password saved in the internal memories.
  • And finally a circuit to keep the OPEN or CLOSE signal for an undetermined time, and of course an output (thats whatever you want to control with your lock)

Step 2: Materials

 
Here´s all that you will need.
NOTE: I took most of the materials from an old VCR board, so they were "free" making this proyect really cheap. In total i spent about 13 dlls (most of the IC cost 76 cnts, exept for the D-ff (about 1.15) cause i had no IC, but you can keep them for future proyects, they are a great investment.
Components:
  • Lots of Diodes (about 20) to make one way connections.
  • One NPN transistor ( to feed the Relay Coil with enough current)
  • One Relay (to control the connected device)
  • One red LED ( to indicate when the system is LOCKED)
  • 14 push buttons
  • Lots of resistors (doesnt really matter the resistance, its just to set the IC pins to 1 or 0[+ or -])
  • Two 7-segments Displays.
  • A Lot of wire!!
 
Integrated Circuits:
  •  Two 7432(OR GATES) to build the DEC to BCD and the comparator
  •  Two 7486(XOR GATES) soul of the comparator.
  •  Two 7447 Display driver
  •  Four 74175(4 D-FF) each is a memory able to hold 4 bits.
  •  One 7476(2 JK-FF) for the display selector and to hold the OPEN CLOSE signal.
  •  One 7404(NOT GATE) invert the clock pulsefor the display selector. ( you could use an NPN transistor insted, cause you need only one gate ( the ic has 6).
 
Tools:
  • 3 Protoboards (http://en.wikipedia.org/wiki/Breadboard)
  • Pliers
  • Exacto Knife
  •  5V DC power supply(feeds circuits)
  • 12V DC power supply(feeds the relay coil)
  • 120V AC Power supply(feeds the device on the output)
NOTE:I used about 8 ft of wire, and advice about this, insted of buying expensive protoboard wire, you could Buy 3 ft of ethernet cable, the strip it, and you will have 8 or 9 wires, each with a diferent color and 3 ft long. (thats exactly what i do, since the normal protoboard wire is about 10 ft per dollar.
But for a buck you could 3.3 ft of ethernet cable, so you would end up with about 27-30 ft!

Step 3: Dec to BCD

 
The first step is building the input system, so you can comunicate with your lock.
I´ve designed the following circuit in order to achive two main goals.
  • Turn any of the 10 numbers from (0-9) to its BCD (binary) counterpart.(Actually, there is an IC for this purpose, but it wasnt in stock when i went to my local electronic shop., so if you get it you will save yourself a lot of time and trouble, but I think is more fun this way )
  • Being able to detect whenever a button is pressed.
To solve the first problem, we should take a look at this truth table to know which output (ABCD) will be high (1) when we press each button.

D C B  A]  X
0  0  0  0]  0
0  0  0  1]  1
0  0  1  0]  2
0  0  1  1]  3
0  1  0  0]  4
0  1  0  1]  5
0  1  1  0]  6
0  1  1  1]  7
1  0  0  0]  8
1  0  0  1]  9
 
Now heres where something I love about Digitals comes to a use…
There are many ways of doing one thing…. Its just like maths, you can get to 3 adding 1+2, or substracting 4-1, or 3^1….
In other words, you could build lots of diferents circuits to achive the same goal, this is something that makes our current task easier.
 
I designed this circuit cause I thought it used few ICs, but you could design your own!
Now, I know some maybe scratching their heads trying to figure out why did I used so many diodes, well here is the answer…
 
Diodes work like a one way connection, so in a pair connected as in my circuit, if there´s (1) voltage on its "positive side" it will conduce current, so we will have voltage in the other side aswell, but if there is a negative , or inexistent voltage (0) it will behave as an open circuit. Lets check the behavior of these diodes, calling the first diode anode (+) "E", and the second diode anode "F" and the output will be their connected cathode"X".

 E F]  X
 0  0]  0
 0  1]  1
 1  0]  1
 1  1]  1
 

 You can see we have the exact same behavior than an OR GATE, and then,Why not using just diodes, that way you will save even more Integrated Circuits, and money?...Well the answer is simple, and you should really take it in consideration, the VOLTAGE DROPPED across EACH DIODE. It´s normally about 0.65V. Why is that? Because each diode needs at least 0.6 V across its anode and cathode to make its junction get close, so it can start conducting.I

In other words, for each diode you connect and its working at the same time, you will loose 0.65 V… that wouldnt be a big problem if we were only turning leds on, but we are working with TTL IC, that means that we need at least more than 2 V. And as we are starting with 5 v.. That means that conecting 5 diodes will cause a failure in our circuit ( the integrated circuit wouldnt be able to distinguish between 0v and less than 2v…)
 
That´s why I never used more than 2 diodes in each input…
 
NOTE: You must connect a resistor connected to GND in each OR Gate input…
 
To solve the second problem I just added a diode to each ABCD, and 0, and connected them together, so whenever any of those is 1, you will have a 1 on "Press"(P).
 
Now all that´s left is to build it on your breadboard, or if you want to save some more space you can do as i did, and drill some holes in a construction paper and solder the diodes and push buttons there...

If you need some more information about Logic Gates:
If you need some more information about diodes:

Step 4: Displays

 

These step is one of the easiest, we just need to decode the ABCD inputs to drive the seven segment display…And luckly there´s already an integrated circuit that will save us all the logic, time and space.

 

If you are using a Common Anode display then you will need a 7447.

If you are using a Common Cathode display then you will need a 7448.

 

The wiring is the same, so either way you could use my schematic.

 

The inputs ABCD for each IC come from each memory´s output (we will review the memories in the next step)

Step 5: Memory

 
This is were we change from combinational logic, to secuencial logic…
To make the 4 bits(ABCD) memory we just need a D- Flip Flop for each bit, and in the 74175 we have 4 of those.
Remember each number is represented in ABCD , so each 74175 can save one number.
 
For more information about how does the D-flipflop works, and how does it saves information,:
 
The input of the first two memories (Data "D") comes from the DEC to BCD coder that we built on the first step.
Well we have the information that each one is going to hold, but, when are they going to save it?
Of course, one will save the first pressed number and the other the second pressed number…
 
So, how do we get this effect? Well with another kind of FF (flip flop) the JK, when both J and K inputs are high, it will change the state of the outputs to its complement (negation), in other words, we will have on "Q" 1, then 0 then 1 again, then 0 and so on. This Q and Q´ are the clock for the memories (what will tell´em when to save new data.)
 
The pulse that will determine when this change is made is the "P" that is high whenever you press any number, but to save the information on time, we will need the opposite, so heres where we use the NOT GATE.
 
In other words, once we push a button, the jk ff will change its output, turnin on the first memory, so that it will save the data, then we push again and the first memory recording state will be off, but the second memory will save the new data!
I added at this point a reset button that will turn both memories (ABCD) back to 0, and will return the display selector (jk ff) to the first memory.
For more information about the JK FF:
 
Now… why did i said we need four 74175?
Well to save the password!! While its possible just to set the password with resistors to GND or Vcc, that will make your password static, and impossible to change if you get your lock done in a PCB.
So, with a memory, you can save the password, and change it as many times as you wish.
 
The inputs will be the outputs of our displays memory, so when a positive pulse reaches their clock, you will be coping whathever numbers are in the displays. (both, the memories and password memories will have the same information). Of course the "new password" pulse will only be avaliable if you already intruduced the correct password and opened the lock.
 
In all we will have a storage capacity of 2 Bytes or 16 bits!!

Step 6: Comparing

 
At this point we have a system thats capable of saving each number we press in one display then the other, and copying that information to the password memories… we are still lacking the essential, the Comparator… one circuit that will compare the two (ABCD) of the display memories with the two (ABCD) of the password memories.. Again, theres already an IC from the TTL family that does all the dirty job, but it wasnt in available in my local electronic shop.
 
So I built my own.
To understand how i did it lets look at the XOR truth table
 
 A  a]  X
 0  0]  0
 0  1]  1
 1  0]  1
 1  1]  0
 
Notice that whenever A and a have the same value, the output is low (0).
So if they are diferent we will have a 1 at the output.
Meaning that with one XOR Gate you can compare 2 bits one of the display memory and the other of the password memory. Based on that i built the following circuit, remember that you can build it your own way, cause there are many ways to get to the same answer here in digital electronics.
 
This circuit takes in the 8 bits of the display memories ( one bit per XOR, cause the other input should be used with the password memory) and the 8 bits of the password memories ( its a 1 Byte comparator).
And will deliver only one output.
 if and only if the information on both display memories is the same as the information in the password memories, we will have a (0) low output. In other words, if the information on both sets of memories differ, even on 1 bit, the output will be high (1).

Step 7: Open/Close

 
Finally the last part, we are almost done! Soon enogh you will be able to lock any device, or electrify any fence,, ( Please dont!)
 
Now, we will take the last bit of information, and interrupt it with a push button, so if someone accidentaly writes the correct password, the lock wont open.( i called this button "enter", really clever, huh!,)
 
And after the enter button,will come the RS latch, one device that can turn Q´ to 1 if a there´s a 0 on its R input, and save it, and Q to 1 if theres a 0 in the S input.
 
For more information on RS latch:
 
I connected "Q" to a red led meaning lock, or that the controlled device is OFF.
And "Q´" to a transistor that will provide the relay with enogh current to turn it, turning ON the controled device.
"Q´" was connected to a push button, ( that i called new password button for obious reasons) so that when you push that button it you will close the circuit between Q´ and the clock input for the password memory. If Q´ is Low (system locked) nothing will change in the password memory when the button is pressed, but if it is High (system Open) clock will be activated and password memories will copy the information on the display memories.(changing the password).
And connected a resistor to GND and to a push button (lock button) and from there to the S input, so whenever you press it, you will lock the system.
 
Well, while i could have bought an RS flip flop just for this purpose, i still got one JK ff left from my 7476.
And, cause the inputs R and S are asincronous, we dont need to worry about the clock. So just wire things up as shown in the diagram ( as i did.)
 
Be Carefull when you connect the relay to AC, use enough isolating tape.. You dont want a short circuit when working with hundreds of volts!
After conecting everithing together…we are finally done!!! Please feel free to comment any question or suggest, if you notice any problem or mistake dont doubt in ponting it out. Im here to help.
Good lock, i mean, good luck with that lock.

Share

    Recommendations

    • Oil Contest

      Oil Contest
    • Water Contest

      Water Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    44 Discussions

    0
    user
    IchW

    1 year ago

    Hello Nino123, one question, You have a complete schematic of the circuit?

    in the images it isn't clear to me

    Hi Nino.. do you have a copy of the whole schematic diagram of this project? because i want to build this but im confused how would i connect all of the schematics that you've posted.. thank you! :D

    Thank you this is very helpful I have 2 questions.

    1) I did not get how to write data to FlipFlop so that It will be there aways?
    if we remove power supply will it Earase?

    2) I did not get ho wopen/close worked . can you give more info on that also

    I have few questions:

    First, there are only 4 outputs from decoder how did you make them into 2 displays ?

    and second, some of the pins you labeled as upper "A" and lower "a", I'm so confused, does that mean they are the same input ?

    2 replies

    Well, you see, upper and lower case A's are indeed different nodes. Lets review a little, The Decimal to Binary circuit outputs a bus of 5 lines, ABCD which represent the binary number and a clock (sincronous output to tell the circuits ahead to act upon the event of pressing a button). Now I simply used that ABCD from the circuit to 2 memory circuits. they will both recieve ABCD data at the same time, but as they are syncronous they will only change their outputs (hold the data) when the clock signal arrives at the CLK pin in the integrated. So theres where the "display selector" comes in, it simply has two outputs for one input, so when ever it recieves the CLK signal from the BCD circuit, it toggles the outputs, therefore toggling which memory 'saves' the button being pressed. So each time you press a button both memory circuits will have the same data in their inputs, but the extra clk output, toggled in the display select will make possible that only one of the memories hold that data, one different display each time. From there on, memory 1 has ABCD outputs to te display decoder1, to the 7 segment 1. memory 2 has abcd outputs to the display decoder2 to the 7 segment 2. The name of this technique is Multiplexing.

    Do you have an email or facebook ?. I've just started to learn digital systems.

    I guess its not that crazy just a place to go where you either have nothing to do or you can only read a book or study just distraction free lockdown or a place to break a bad habit or learn to live moderatly kinda like sensory depravation just more like a controled environment it still seems borderline crazy but I think I could relax and focus idk

    1 reply

    Not crazy at all bro, sometimes the world is just too noisy, how can we read a good book, enjoy good music or just plain think about our own life?, Sounds like a good proyect, but i personally think that is kinda dangerous to do the lockdown system yourself... Even if you are a PRO at electronics, what if something goes wrong? I recommend you build the safe room yourself and everything else inside, but things like ventilation, electricity internet and locks get a professional :D

    This might sound uber insane but sometimes I just need to be locked up for my own good. I was considering using a vault like room kinda like a bomb shelter i have on my property and locking it from the inside with a digital countdown timer able to set for 10 to 14 days mabe longer controlling a electronic door lock somthing like a timed safe only for me. mabe insane could be useful. During this time would need food and water rations dispensed in appropriate amounts was thinking most simple failsafe system if anyone knows of anything or any instructables realated or can help please do

    nino, how to connect all this circuit? especially the display memories circuit. I don't understand it with the internal memories. does it came together in display memories circuit? thank you.

    1 reply

    Hey, sorry again for the late reply, finals are killing me, but well thats what you have to go through to be an engineer! Well, about how to connect it... Most of the diagrams I posted, came from a software which not only numbered each pin, but also named it; in order to be able to understan that, you need to know your ICs, and by that I mean reading the datasheet, and understanding the basic operation of your IC, and how to use each pin. I strongly recommend, that you practice easier circuits with each IC, just to get used to the Pinout and the way they work, and then youll be able to make any bigger project using as many as you need, after all, if you learn the alphabet youll be able to write poems, books or just about anything after practicing, the same applies here.
    The 74175 is just as any other TTL IC, you have to power it with 5v, ground, and in this case, youll have to give it a signal that will trigger the change of state on the outputs(which will remain on that state indeterminately), acording to your inputs (which youll control on the keypad) . In this case, the output are coded to BCD, and then translated from that to a 7segment display "language" by our 7447

    I'm sorry. actually I posted once only. Don't know how it repeated again. By the way, thank you very much for your explanation. I will seek your advice if I stuck at somewhere later. :D Thank you once again.

    1 reply

    this is my new account from azaki-1. thank you.

    hi. I have same project with you where I have to build digital combination lock. I just want to confirm with you which is my project need to enter 4 numbers, and reconfirm again the number input. If correct, then it will light up GO LED. if not, NOT GO LED. So, it is my project almost same to you or not. Thank you in advance, and really need your explanation on your projects.

    1 reply

    I answered on the last comment reply, but It has been a lot of time since the last time I used Digital circuits, I can totally tell you that using a Pic, PICAXE, Arduino, Parallax, or any other microcontroller would make your whole proyect really easy. Its easier to learn how to program (and maybe cheaper) a microcontroller that learning digitals. But if you, (like in my case) MUST use Digital Circuits (TTL 74XXX) I hope my proyect serves as a guide, If you really need more help, you can send me a Personal Message, Ill try to answer as soon as I can, just be patient, Im an engineer student, I have not a lot of free time.

    hi. I have same project with you where I have to build digital combination lock. I just want to confirm with you which is my project need to enter 4 numbers, and reconfirm again the number input. If correct, then it will light up GO LED. if not, NOT GO LED. So, it is my project almost same to you or not. Thank you in advance, and really need your explanation on your projects.

    1 reply

    Yes it really almost the same. On the output, the led that will go or will not go out is just the same as my Relay for 110v, instead of wiring the relay to the output, just connect the led directly where the Q or Q' depending on your case. If you want it to be a 4 number combination lock, youll have to add two more displays, decoder(7447), memory(74145) and comparation blocks (7486). To make it double confirmation, you can add another flipflop (7476) before the led, so youll need two "clocks" (correct number on the input) for your last jk flipflop to turn the Q' ON.

    hi. I have same project with you where I have to build digital combination lock. I just want to confirm with you which is my project need to enter 4 numbers, and reconfirm again the number input. If correct, then it will light up GO LED. if not, NOT GO LED. So, it is my project almost same to you or not. Thank you in advance, and really need your explanation on your projects.

    I also would like to ask if you can suggest a circuit with these functions:
    Code Breaker
    Three digit code (0-9)
    Three LEDs for right number but wrong position (red)
    Three LEDs for right number and wrong position (green)
    One digit display for the number of tries
    One increment button for each digit
    One GUESS button
    One STORE button for new code
    Switch debouncing using 555 timers or one shot multivibrators
    Master reset button

    thank you very much i would really appreciate it if you would respond with this post...