Lesson 70: Gates from switches
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
Logic you can build
- Logic gates are made from tiny electronic switches. You can build the idea with two push buttons.
- Series: one button after the other. The current needs both: that is AND.
- Parallel: two buttons side by side. Either one is enough: that is OR.
| A | B | AND (series) | OR (parallel) |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
- 1 means the button is pressed, or the LED is on.
- The 10 kΩ pull-down resistor makes D2 read 0 when no path to 5V is closed (lesson 25).
In the exam
- 0478/22/M/J/23 Q2: link each logic gate (AND, OR, NAND, NOT) to its standard symbol. AND has a flat back and a round front; OR has a curved back and a pointed front.
- Use the table above for the AND and OR truth tables. Lesson 42 tests all six gates with code.
Difficulty 3/5 · 200 coins + a small bonus on first completion today
Build an AND gate from two buttons. Put them in series, one after the other, between the 5V row and the D2 row, and add a 10 kΩ pull-down resistor from D2 to GND (as in lesson 25). The sketch copies D2 to the LED on D13, which is already wired. The LED should light only when both buttons are pressed.
Click Run to see the output here.
Difficulty 3/5 · 200 coins + a small bonus on first completion today
Now an OR gate: put the two buttons in parallel, side by side, each one from the 5V side to the D2 side. Keep the pull-down resistor. The LED should light when A or B (or both) is pressed.
Click Run to see the output here.