Vol. DIY Electronics Projects
Chapter 7 Digital IC Projects

Digital Lab - Digital Combination Lock

In this hands-on electronics experiment, build a digital combination lock with LED output indicators and learn about XOR gate functionality and how to implement NOR logic functionality using diodes.

Project Overview

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.  


Breadboard implementation of the digital combination lock with LED output indicators.

Figure 1. Breadboard implementation of the digital combination lock with LED output indicators.


Parts and Materials

  • 4001 quad NOR gate
  • 4070 quad XOR gate
  • Two eight-position DIP switches
  • Two LEDs
  • Four 1N914 switching diodes
  • Ten 10 kΩ resistors
  • Two 470 Ω resistors
  • Pushbutton switch, normally open
  • Two 6 V batteries

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."


Learning Objectives

  • To use XOR gates as bit comparators
  • How to build simple gate functions with diodes and a pull-up/down resistor
  • Using NOR gates as controlled inverters



Step 1: Build the circuit, as illustrated in Figure 1, with the matching schematic diagram of Figure 2. 


Schematic diagram of the digital combination lock with LED output indicators.

Figure 2. Schematic diagram of the digital combination lock with LED output indicators.


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.


Explanation of Operation

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).


Table 1. XOR truth table
0 0 1
0 1 0
1 0 0
1 1 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!


Related Content

Learn more about the fundamentals behind this project in the resources below.