This project uses DIP switches and combinational logic circuits to implement a digital combination lock. As illustrated in Figure 1, the circuit has green and red light-emitting diodes (LEDs) that indicate whether or not the data entry code matches the key code.
Caution! Both the 4001 and 4070 ICs are complementary metal-oxide semiconductors (CMOS) and, therefore, sensitive to static electricity!
This experiment may be built using only one 8-position DIP switch, but the concept is easier to understand if two switch assemblies are used. The idea is that one switch holds the correct code for unlocking the lock while the other switch serves as a data entry point for the person trying to open the lock.
In real life, of course, the switch assembly with the key code set on it must be hidden from the sight of the person opening the lock, which means it must be physically located elsewhere from where the data entry switch assembly is. This requires two switch assemblies. However, if you understand this concept clearly, you may build a working circuit with only one 8-position switch, using the left four switches for data entry and the right four switches to hold the key code.
For extra effect, choose different LED colors: green for "Go" and red for "No Go."
Step 1: Build the circuit, as illustrated in Figure 1, with the matching schematic diagram of Figure 2.
This circuit illustrates using XOR (Exclusive-OR) gates as bit comparators.
Step 2: Set the key code for the system by configuring the four key code switches.
Step 3: Set the data entry switches to match the key code. Then, press the ENTER button. The green "Go" LED should light up while the ENTER button is held down.
Step 4: Set the data entry switches to a configuration different from the key code. Then, press the ENTER button. The red "No Go" LED should light up while the ENTER button is held down.
The four XOR gates connected to the switches compare the respective bits of two 4-bit binary numbers, each number entered into the circuit via a set of switches. If the two numbers match, bit for bit, the green "Go" LED will light up when the ENTER button switch is pressed. If the two numbers do not exactly match, the red "No Go" LED will light up when the ENTER button is pressed.
Since four bits provide a mere sixteen possible combinations, this lock circuit is not very sophisticated. If it were used in a real application such as a home security system, the "No Go" output would have to be connected to some siren or other alarming device so that the entry of an incorrect code would deter an unauthorized person from attempting another code entry. Otherwise, it would not take much time to try all combinations (0000 through 1111) until the correct one was found!
Keep in mind that in this experiment, I do not describe how to work this circuit into a real security system or lock mechanism, but only how to make it recognize a pre-entered code.
The “key” code that must be matched at the data entry switch array should be hidden from view, of course. If this were part of a real security system, the data entry switch assembly would be located outside the door, and the key code switch assembly behind the door with the rest of the circuitry. In this experiment, you will likely locate the two switch assemblies on two different breadboards, but it is entirely possible to build the circuit using just a single (8-position) DIP switch assembly. Again, the purpose of the experiment is not to make a real security system but merely to introduce you to the principle of XOR gate code comparison.
It is the nature of an XOR gate to output a high (1) signal if the input signals are not in the same logic state, as illustrated in the following logic truth table (Table 1).
The four XOR gates’ output terminals are connected through a diode network which functions logically as a four-input OR gate. If any of the four XOR gates outputs a high (1) signal—indicating that the entered code and the key code are not identical—then a high (1) signal will be passed on to the input of the NOR gate logic. If the two 4-bit codes are identical, then none of the XOR gate outputs will be high (1), and the pulldown resistor connected to the common sides of the diodes will provide a low (0) signal state to the NOR logic.
The NOR gate logic performs a simple task: prevent either of the LEDs from turning on if the ENTER pushbutton is not pressed. Only when this pushbutton is pressed can either of the LEDs energize.
If the ENTER switch is pressed and the XOR outputs are all low, the "Go" LED will light up, indicating that the correct code has been entered. If the ENTER switch is pressed and any of the XOR outputs are high (1), the "No Go" LED will light up, indicating that an incorrect code has been entered.
Again, if this were a real security system, it would be wise to have the "No Go" output do something that deters an unauthorized person from discovering the correct code by trial and error. In other words, there should be some penalty for entering an incorrect code. Let your imagination guide your design of this detail!
Learn more about the fundamentals behind this project in the resources below.
In Partnership with Future Electronics
by Jake Hertz