Combination Lock (XOR + NOR Gates) – B2P17

We will now look at two new logic gates and we will use them to create an extremely basic combination lock.

Combination lock

The 74HC86 consists of 4 XOR gates which have 2 inputs each. The output of an XOR gate is LOW when both the inputs are the same (either HIGH or LOW) and the output is HIGH in all other cases.

Combination lock

The 74HC02 consists of 4 NOR gates which have two inputs each. The output of a NOR gate is HIGH when both the inputs are LOW and the output is LOW in all other cases.

The combination lock works on the following principle. We have a known good combination, also called the key which is compared to the user input. If the two are a match, then the green LED will glow, otherwise, the red LED will glow.

Combination lock

Let’s assume that SW1 is the key, while SW2 is the user input. We’ve added pull-down resistors to give us a known LOW state and all these switches are connected as inputs to the XOR gate in pairs. This means that switch 1 from both SW1 and SW2 are connected to the same XOR gate and so on. The outputs of all 4 XOR gates are connected to 4 diodes which are then connected to a pull-down resistor. If all 4 user input switches match the reference key, then the outputs of all 4 XOR gates will be LOW. In all other cases, the combined output will be HIGH which will cause a voltage drop across R10. This output voltage is used as the input for the 74HC02 NOR gates.

Combination lock

The output is first fed into both the inputs of the first NOR gate. This results in the signal being inverted and this is fed into input A of the second NOR gate. Input 2B is connected to the switch which pulls the pin LOW when pressed. NOR gate 2 is responsible for controlling the ERROR LED. If the user input did not match the key, then the output from the XOR IC would be HIGH. This is inverted by the first gate to give us a logic LOW. This logic LOW will be compared with the logic LOW input from the switch, and the resulting NOR operation would give us a logic HIGH which would cause the ERROR LED to glow. In all other cases, the ERROR LED would receive a logic LOW, keeping it OFF.

Input 3A directly receives the output from the XOR gate, while input 3B receives the input from the switch. If the user input matched the key, then the XOR IC output would be LOW. This LOW value would be compared with the LOW value from the key and the resulting NOR operation would be a logic HIGH which would cause the OK LED to glow. In this way, we can demonstrate the working of a very simple 4-bit combination lock.

Combination lock

Here’s what the assembled PCB looks like. Please ensure that the ICs are placed with the right orientation. This project demonstrates the principles of logic gates and in reality, the combination lock would have to have much more than 16 combinations for it to be effective. It would be much easier to use a numeric keypad along with a microcontroller to set and verify the user entered key. All logical operations can be carried out with software, preventing the need for external logic ICs. Let’s move on to the next project.