Introduction: Hardware-Based Keypad Lock
Theory of operation:
You set the code with the headers you see at the bottom left of the board in the picture. If you hit a wrong button, the part of the code you have entered correct so far will be reset. If you mess up a certain amount of times the keypad will lock and can only be unlocked by pressing the button you see at the bottom right corner of the large board. The count of how many times the code has been entered incorrectly is reset once you enter the correct code. Each time you press the correct button the corresponding red LED will light.
Things I would like to improve:
The only thing I would like to change about this lock is to make it so that you can't enter the code in any order. For example, as the circuit is now, if the code was 2, 1 you could also enter it as 1, 2.
I had to substitute some components that I did not have for others. For example, instead of an AND gate, I used a NAND gate in conjunction with a NOT gate at its output.
Step 1: Parts/Tools List
(2) Triple three input NAND gate ICs + (1) 74HC04 hex inverter OR (2) triple three input AND gates such as the 74HC11
(1) 74HC04 hex inverter
(1) 74HC30 8-input NAND gate
(2) CD4077 quad 2 input XNOR gate
(6) 555 timers
(6) 100μF electrolytic capacitors
(6) 0.01μF ceramic capacitors
(6) 1K ohm resistors
(6) 2n2907 PNP transistors
(16) 2n2222 NPN transistors
(1) 5V SPDT relay
(1) 1N4001 diode
(36) 10K ohm resistors
(7) 100K ohm resistors
(7) 470 ohm resistors
(7) Momentary push button switches
(6) Red LEDs
(1) White LED
(2) 6 pin male headers
5V power source such as a cell phone charger
Various colors of wire
Rosin core solder
(optional) Desoldering iron
Step 2: Component Placement
Here is a close up showing how I arranged my parts.
Step 3: Schematic
For simplicities sake, I'll just show 2/6th of the schematic since the entire lock is basically the same circuit 6 times. The full sized schematic can be viewed here.
Explanation of circuit:
The 555 timer circuit delays the signal going to the clock pin of the 74HC74 flip flop so that it meets the set up time specified by the flip flop. "Set up time" means that the data signal has to be present for a certain amount of time before the positive going edge of the clock signal. There is also a thing called "hold time" this is a flip flop timing parameter that says the data signal should be present a little longer than the clock signal. In my circuit I violate hold time, but it still works just fine. If you violate set up time you'll find that the flip flop's output will act erratically.
The XNOR gate, IC2A, will output a positive voltage if both the inputs are the same. Now let's take a look at IC3 and IC1A. When the input of IC3 is 0 and the other input of IC1A is 1 the output of IC1A will be 1 which means the output of Q2 will be 1 which in turn will switch on Q4 allowing current to flow through the relay coil which will reset the flip flops. The reason for Q2 is that if all the AND gates outputs were connected to the same point, it could cause a short if one output was 1 and one was 0 which would destroy the chip. IC 10 is the well-known 4017 decade counter. Every time you "mess up" when you input the code, it advances the counter by 1, when it reaches pin 10, Q9 is turned on which will lock the keypad. You can change how many tries you have before the keypad locks by changing which pin you connect the base of the transistor to on the 4017. Note that only the 555s and flip flops should be connected to the relay's common terminal, all other power connections should be made at VCC.
It might be a good idea to include pull down resistors on the inputs of IC5, however, I have not found this to be a problem.
Step 4: Final Thoughts
Have fun with your new hardware-based keypad lock! Keep in mind that this should never be used in place of a real lock.
We have a be nice policy.
Please be positive and constructive.