Year 9 · Summer 1
Physical Computing · Lesson 3 of 5
Signals between devices
PracticalTopic 9 Logic gates
Year 9 · Physical Computing · Lesson 3 of 5
You will learn to
- Explain that a digital signal is a voltage that is either high (1) or low (0).
- Build AND, OR and XOR with two buttons and three LEDs, and test all four input pairs.
- Fill in a truth table from what the LEDs show.
- Explain how the same logic works in code (&&, ||, !=) and in a real gate chip.
Year 9 · Physical Computing · Lesson 3 of 5
Success criteria
You have got it when you can say:
- I can test all four button combinations and record each LED.
- I can say which LEDs light when only button A is pressed.
- I can match each line of the code to its gate.
Year 9 · Physical Computing · Lesson 3 of 5
Retrieval starter
Questions from before. Write your answers, then show them.
- Last lesson
A CPU runs at 2 GHz. How long is one tick?
A 0.5 nsB 2 nsC 0.2 ns
A. 0.5 ns
- Last unit
A 10 × 10 black-and-white image needs…
A 100 bitsB 10 bitsC 20 bits
A. 100 bits
- Earlier this year
To show change over time, use a…
A Scatter graphB Pie chartC Line chart
C. Line chart
Year 9 · Physical Computing · Lesson 3 of 5
Key words (1 of 2)
- Boolean
- A value that is only True or False.
- Logic gate
- A tiny circuit that takes bits in and gives one bit out by a fixed rule.
- Truth table
- Lists every input combination and its output.
- Boolean expression
- A rule written with AND, OR and NOT that gives True or False, like A AND NOT B.
Year 9 · Physical Computing · Lesson 3 of 5
Key words (2 of 2)
- Half adder
- An XOR gate plus an AND gate: adds two bits.
- Transistor
- An electronic switch with no moving parts.
The explanation · step 1 of 4 · part 1 of 2
Signals: high or low
A signal is a message carried by electricity. A digital signal has only two levels.
| Level | Voltage on an Arduino Uno | Means |
|---|---|---|
| HIGH | 5 V | 1, true, on |
| LOW | 0 V | 0, false, off |
An input pin listens for a signal. digitalRead(2) gives 1 if pin 2 is HIGH, and 0 if it is LOW.
The explanation · step 1 of 4 · part 2 of 2
Signals: high or low (continued)
Why does each button need a 10 kΩ resistor?
With the button up, the pin is joined to nothing. It can drift between 0 and 1. The resistor gently pulls it down to 0. Pressing the button joins the pin to 5 V, which wins. This is a pull-down resistor.
The explanation · step 2 of 4 · part 1 of 2
Three gates, two buttons
Button A goes to pin 2. Button B goes to pin 3. Each LED shows one gate's answer.
| A | B | AND (green, pin 10) | OR (blue, pin 11) | XOR (yellow, pin 12) |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 |
The explanation · step 2 of 4 · part 2 of 2
Three gates, two buttons (continued)
- AND: on only when both buttons are pressed.
- OR: on when at least one button is pressed.
- XOR: on when the buttons are different.
Two inputs make 2² = 4 rows. Test all four, or you have not tested the gate.
The explanation · step 3 of 4 · part 1 of 3
The same logic in code, and in a chip
void loop() {
int a = digitalRead(A_PIN); // 1 = pressed, 0 = not pressed
int b = digitalRead(B_PIN);
digitalWrite(AND_LED, a && b); // AND: both
digitalWrite(OR_LED, a || b); // OR: at least one
digitalWrite(XOR_LED, a != b); // XOR: different
delay(200);
}The explanation · step 3 of 4 · part 2 of 3
The same logic in code, and in a chip (continued)
| C++ | Read it as | Gate |
|---|---|---|
a && b | a and b | AND |
a || b | a or b | OR |
a != b | a is not equal to b | XOR |
Stage 2 of the build uses no code at all. A 74HC08 chip holds four AND gates, made of transistors.
A 74HC32 chip holds OR gates. A 74HC86 chip holds XOR gates. Their pins are the same, so you can swap them.
The explanation · step 3 of 4 · part 3 of 3
The same logic in code, and in a chip (continued)
A chip needs power too: pin 14 to the + rail and pin 7 to the − rail. Without them it does nothing.
The explanation · step 4 of 4 · part 1 of 4
Messages between two boards (micro:bit)
Two micro:bits can send signals to each other by radio. Both must use the same group number, like a channel.
The explanation · step 4 of 4 · part 2 of 4
Messages between two boards (micro:bit) (continued)
from microbit import *
import radio
radio.on()
radio.config(group=7) # both boards use group 7
while True:
if button_a.was_pressed():
radio.send("A") # send a message
message = radio.receive()
if message == "A": # a message arrived
display.show(Image.YES)
sleep(500)
display.clear()The explanation · step 4 of 4 · part 3 of 4
Messages between two boards (micro:bit) (continued)
- Put the same program on both boards.
- Press A on one board. It sends the message "A".
- The other board checks for messages every time round the loop.
- When "A" arrives, it shows a tick for half a second.
Both boards follow the same rules: the same group and the same messages. That is a protocol.
The explanation · step 4 of 4 · part 4 of 4
Messages between two boards (micro:bit) (continued)
These radio messages are not encrypted. Any micro:bit on the same group can read them.
Year 9 · Physical Computing · Lesson 3 of 5
Worked example
Button A is pressed and button B is not. Which LEDs light?
- Write the inputs: A = 1, B = 0.
- AND needs both to be 1. B is 0, so AND = 0. Green is off.
- OR needs at least one 1. A is 1, so OR = 1. Blue is on.
- XOR needs them to be different. 1 and 0 are different, so XOR = 1. Yellow is on.
- Check on the board: hold A only. Blue and yellow light.
Year 9 · Physical Computing · Lesson 3 of 5
Try it: Play with logic gates
Year 9 · Physical Computing · Lesson 3 of 5
Quick quiz · 1 of 3
How many rows in a truth table with 3 inputs?
- A 8
- B 6
- C 3
A. 8
2³ = 2 × 2 × 2 = 8.
Year 9 · Physical Computing · Lesson 3 of 5
Quick quiz · 2 of 3
Which gate gives 1 only when its two inputs are different?
- A NAND
- B OR
- C XOR
C. XOR
XOR = exclusive OR. 0,1 and 1,0 give 1; 0,0 and 1,1 give 0.
Year 9 · Physical Computing · Lesson 3 of 5
Quick quiz · 3 of 3
In AQA notation, what does A + B mean?
- A A add B
- B A AND B
- C A OR B
C. A OR B
AQA uses + for OR, . for AND, ⊕ for XOR and an overbar for NOT.
Year 9 · Physical Computing · Lesson 3 of 5
Exit ticket
Answer on paper before you go. Then check.
A half adder is made from…
A an XOR gate and an AND gateB a NOT gate and an OR gateC two OR gates
A. an XOR gate and an AND gate XOR gives the sum bit; AND gives the carry bit.
Q = (A OR B) AND NOT C. With A = 0, B = 1, C = 1, Q is…
A 0B 1
A. 0 A OR B = 1. NOT C = 0. 1 AND 0 = 0.