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.