Logic Gates
What are Logic Gates?
Digital logic circuits can be broken down into two subcategories- combinational and sequential. Combinational logic changes “instantly”- the output of the circuit responds as soon as the input changes. Sequential circuits have a clock signal, and changes propagate through stages of the circuit on edges of the clock.
To the right is logic in action. Using a 555 timer with internal logic gates and other electronic components, we can create some pretty cool electronic projects!
Common Gates
AND gate
Output is 1 if BOTH inputs are 1
OR gate
Output is 1 if AT LEAST one input is 1
XOR gate
Output is 1 if ONLY one input is 1
NOR gate
Output is 1 if BOTH inputs are 0
NAND gate
Output is 1 if AT LEAST one input is 0
XNOR gate
Output is 0 if ONLY one input is 1
NOT gate
Output of a NOT gate inverter is a 1 if the input is a 0, and vise versa.
Buffer
Output is the same as input. Space filler.
Boolean Algebra
Boolean algebra is a mathematical structure and set of operations used in digital logic design and computer science. It was introduced by mathematician and logician George Boole in the mid-19th century. Boolean algebra deals with binary variables and operations, where variables can only take on one of two possible values: true (often represented as 1) or false (represented as 0).
Boolean algebra follows specific rules and laws, such as:
Commutative Law: A⋅B=B⋅A, A+B=B+A
Associative Law: (A⋅B)⋅C=A⋅(B⋅C), (A+B)+C=A+(B+C)
Distributive Law: A⋅(B+C)=(A⋅B)+(A⋅C), A+(B⋅C)=(A+B)⋅(A+C)
Boolean algebra is fundamental to the design and analysis of digital circuits. It provides a mathematical framework for expressing and manipulating logical expressions, helping engineers and designers to simplify and optimize complex logical circuits. Additionally, Boolean algebra is closely related to binary arithmetic and forms the basis for programming and computer science concepts such as binary code, truth tables, and logic gates.
Logic and Truth Tables
Truth tables are simple plots that explain the output of a circuit in terms of the possible inputs to that circuit. Here are truth tables describing the six main logic gates:
What is Inside a Logic Gate?
Logic gates are made of other electronic components like diodes, resistors, transistors, and MOSFETS, a type of transistor. Most logic gates can be made in more than one way using a combination of different components. Pictured below is an AND gate made three ways:
Build Your Own Logic Gates!
Almost everything a CPU can do can be reduced to some sort of logic equation. In math and theoretical computer science, the most common logic operations are AND, OR, and NOT. From an electrical point of view NOR and NAND gates are far more popular.
In theory, every logic operation can be performed using only NAND gates. In practice, it is more useful to use other gates as well. The following exercises will describe and demonstrate how the different gates can be implemented using transistors for AND, OR, NOT, NOR, and NAND gates.
In these exercises, you will construct the logic gates that you will find inside the ICUs of future projects. You will find that logic gates are made up of a combination of transistors and resistors where ICUs are made up of a combination of logic gates and further resistors.
You will use the following schematics to create and test your built logic gates.
Exercise 1: AND Gate
Background Knowledge:
How to read a Schematic
How to use a Breadboard
How to read and use a Multimeter
All Basic Electronics Projects
Logic Gates
What you'll need:
1 - 5V Power Supply
1 - Positive and Negative Alligator Clips
1 - Breadboard
2 - 3904 NPN Transistors
3 - 10K Ohm Resistor
1 - 4 Pin DIP Switch
1 - 5mm Red LED
1 - Jumper Wire Set
What to Expect:
When you complete this circuit the LED will only turn on if you’ve met the correct conditions for the AND Gate. If the LED turns on when only the Input B is closed, slowly lower the resistor value of the 10K Resistor that is in parallel with the LED until it turns off. This should be no lower than 1K minimum.
How it Works:
You have two NPN transistors in series. In order for current to flow through both, the base leg of both transistors must have current flowing into them.
When you close the open switches you simulate the input on the legs of the AND Gate, you allow current to flow to the base legs of their corresponding transistors.
For the AND Gate, both switches must be closed and on to meet the gate’s conditions.
Questions:
Why are the transistors NPN and not PNPs?
What is the 10K resistor that is in parallel with the LED for?
What would the state of the LED be in the following truth table?
Exercise 2: OR Gate
Background Knowledge:
How to read a Schematic
How to use a Breadboard
How to read and use a Multimeter
All Basic Electronics Projects
Logic Gates
What you'll need:
1 - 5V Power Supply
1 - Positive and Negative Alligator Clips
1 - Breadboard
2 - 3904 NPN Transistors
3 - 10K Ohm Resistor
1 - 4 Pin DIP Switch
1 - 5mm Red LED
1 - Jumper Wire Set
What to Expect:
When you complete this circuit the LED will only turn on if you’ve met the correct conditions for the OR Gate.
How it Works:
You have two NPN transistors in parallel. Current will flow through to the LED if the base leg has current flowing into it.
When you close the open switches you simulate the input on the legs of the OR Gate, you allow current to flow to the base legs of their corresponding transistors.
For the OR Gate, either switch or both must be closed and on to meet the gate’s conditions.
Questions:
Why are the transistors in parallel and not series?
What would the state of the LED be in the following truth table?
Exercise 3: NOT Gate
Background Knowledge:
How to read a Schematic
How to use a Breadboard
How to read and use a Multimeter
All Basic Electronics Projects
Logic Gates
What you'll need:
1 - 5V Power Supply
1 - Positive and Negative Alligator Clips
1 - Breadboard
1 - 3904 NPN Transistors
1 - 470 Ohm Resistor
1 - 10K Ohm Resistor
1 - 4 Pin DIP Switch
1 - 5mm Red LED
1 - Jumper Wire Set
What to Expect:
When you complete this circuit the LED will only turn on if you’ve met the correct conditions for the NOT Gate.
How it Works:
You have one NPN transistor in series. Current will flow through to the LED unless the transistor is closed making electricity take the path of least resistance straight to ground.
When you close the open switch you simulate the input on Input A of the NOT Gate, and you allow current to flow to the base legs of the corresponding transistor.
For the NOT Gate, there needs to be no input to meet the gate’s conditions.
Questions:
How does this work?
What is another schematic you could draw without a transistor that would also be a NOT gate?
What would the state of the LED be in the following truth table?
Exercise 4: NAND Gate
Background Knowledge:
How to read a Schematic
How to use a Breadboard
How to read and use a Multimeter
All Basic Electronics Projects
Logic Gates
What you'll need:
1 - 5V Power Supply
1 - Positive and Negative Alligator Clips
1 - Breadboard
2 - 3904 NPN Transistors
1 - 470 Ohm Resistor
2 - 10K Ohm Resistor
1 - 4 Pin DIP Switch
1 - 5mm Red LED
1 - Jumper Wire Set
What to Expect:
When you complete this circuit the LED will only turn on if you’ve met the correct conditions for the NAND Gate.
How it Works:
You have two NPN transistors in series. Current will flow through to the LED unless both transistors are closed making electricity take the path of least resistance straight to ground.
When you close the open switches you simulate the input on the legs of the NAND Gate, you allow current to flow to the base legs of their corresponding transistors.
For the NAND Gate, both switches are open and off to meet the gate’s conditions.
Questions:
Why does the LED turn off when both transistors are closed and have current flowing through them?
Why is there a resistor in front of the LED in this case?
What would the state of the LED be in the following truth table?
Exercise 5: NOR Gate:
Background Knowledge:
How to read a Schematic
How to use a Breadboard
How to read and use a Multimeter
All Basic Electronics Projects
Logic Gates
What you'll need:
1 - 5V Power Supply
1 - Positive and Negative Alligator Clips
1 - Breadboard
2 - 3904 NPN Transistors
1 - 470 Ohm Resistor
2 - 10K Ohm Resistor
1 - 4 Pin DIP Switch
1 - 5mm Red LED
1 - Jumper Wire Set
What to Expect:
When you complete this circuit the LED will only turn on if you’ve met the correct conditions for the NOR Gate.
How it Works:
You have two NPN transistors in parallel. Current will flow through to the LED unless either or both transistors are closed making electricity take the path of least resistance straight to ground.
When you close the open switches you simulate the input on the legs of the NOR Gate, you allow current to flow to the base legs of their corresponding transistors.
For the NOR Gate, either or both switches are open and off to meet the gate’s conditions.
Questions:
Why are the transistors in parallel instead of series?
What would the schematic for this circuit using PNP transistors instead look like?
What would the state of the LED be in the following truth table?
Check out our Electronics Projects page for fun projects with Integrated Circuits that use Logic!