Logic gates and truth tables
16 minutes · Advanced
Simulations and quizzes aren't read aloud; pause when you reach them and try them out.
A microcontroller contains millions of transistors, but they're all built from a few simple building blocks: logic gates. In this course you'll learn the foundations of digital electronics from gates to counters, and at the end you'll build an electronic die using only ICs, without writing any code. This knowledge is also the foundation of the next course, on microcontrollers.
The digital world: 0 and 1
In digital circuits a voltage carries only two meanings: above a certain level it's 1 (HIGH, true), below a certain level it's 0 (LOW, false). Values in between are undefined and should never occur in a good design. This simplicity makes digital circuits robust against noise.
The basic gates
AND
Output 1 if all the inputs are 1. "A and B"
OR
Output 1 if at least one of the inputs is 1. "A or B"
NOT
A single input. The output is the inverse of the input.
NAND
The inverse of AND. Output 0 if all the inputs are 1, 1 in every other case.
NOR
The inverse of OR. Output 1 if all the inputs are 0.
XOR (exclusive OR)
Output 1 if the inputs differ. Used for comparing and adding two bits.
Try it yourself
Choose a gate, change the inputs and watch the current row light up in the truth table. Memorize the shapes of the symbols too; you'll meet them in schematics all the time.
| A | B | Y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Tipik entegre: 74HC08
NAND can do everything
NAND and NOR gates are universal: all the other gates can be built from NAND gates alone.
- NOT: join the two inputs of a NAND. A NAND A = NOT A.
- AND: add a NOT made from a NAND to the output of a NAND.
- OR: NOT the two inputs separately, then NAND them (De Morgan's law, next lesson).
That's why you can build all the logic of a small circuit with a 74HC00 (four NAND gates). IC manufacturers also usually build the insides of chips from NAND and NOR structures.
Logic ICs
Gates come four to a 14-pin DIP IC (six for NOT). On almost all of them pin 14 is VCC and pin 7 is GND. Which pins belong to which gate is shown in the "pinout" drawing in the datasheet.
Floating inputs
On CMOS ICs (74HC, CD4000) the inputs of unused gates are never left floating. A floating input takes random values, and the gate draws unnecessary current and can heat up. Connect inputs you don't use to GND or VCC. Remember the "floating" button pin from the Arduino course: it's the same thing.Test yourself
1. With A = 1 and B = 0, what is the output of an AND gate?
2. Which gate gives 1 when the inputs differ?
3. Which gate can build all the gates on its own?
4. On 14-pin 74HC-series logic ICs, which pins usually carry the supply?
This was the free first lesson of the course
The remaining 7 lessons of Digital Logic Circuits, with their simulations and quizzes, unlock when you buy the course.
See the full course →