Students hold and release a button wired from 3V to pin 0, see digital read give 1 and 0, trace what pin 0 is joined to in each state, remove the pull-down resistor to see the pin float, and put the reading-and-reacting program in order.
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
SlidesDownload Present from the browser, or export to PowerPoint or PDF.
WorksheetDownload Print the student copy; the Teacher edition has the answers.
Students will be able to
I can explain what digital read gives for 3.3 V and 0 V.
I can explain why a button needs a pull-down (or pull-up) resistor.
I can put a program in order that reacts to a button.
Timing
Predict and Try 6 min · Worked example 10 min · Vary 8 min · Tinkercad 8 min · Practise and Make 8 min
Before class
Model: digital read gives 1 for 3.3 V and 0 for 0 V; a floating pin is shown reading at random every half second. Real floating pins are less tidy (they drift with nearby wires and fingers). A real micro:bit may already turn on a weak internal pull-down when it reads a pin (MakeCode's set pull pin block changes it), so Sam's doorbell may behave on a micro:bit; the external resistor makes the reading definite, and most other boards (Arduino in the next unit) need one. The micro:bit's own buttons A and B are already wired with resistors.
If you have kits: a breadboard, a pushbutton, a 10 kΩ resistor and three jumper wires to an edge connector breakout.
Running the lesson
Predict: students who chose 3.3 are mixing up the voltage and the reading.
Worked example: ask what pin 0 is joined to, in each state, before revealing the lines.
Vary: watch the faces when the heart flickers by itself.
Practise, pull-up: draw both side by side.
The hard part (on purpose)
'Joined to nothing means 0' feels obvious. Let the floating pin surprise them on the board, then ask what the resistor gives the pin.
When students get stuck
What you will see
A question to ask
The fix
A student thinks pin 0 reads 3.3.
Digital read gives one of two numbers. Which?
1 for 3.3 V, 0 for 0 V.
A student thinks the pull-down stops the button working.
Which is a stronger join to pin 0: the button or a 10 kΩ resistor?
The button: it is a direct join.
Answers to the checks
press it: The button joins 3V to pin 0 while you hold it. While you hold it, digital read pin P0 gives… 1. Holding the button joins pin 0 to 3.3 V, and digital read reports that as 1.
Hold: Hold the button. What does pin 0 read, and what does the micro:bit show?
1, and a heart: the button joins pin 0 to 3.3 V.
Let go: Let go. And now?
0, and the screen clears: the pull-down resistor joins pin 0 to GND.
What is pin 0 joined to?: While the button is held, pin 0 is joined to 3V through the button and to GND through the 10 kΩ pull-down. Why does it read 1? The button joins it straight to 3V; the 10 kΩ only lets a tiny current leak to GND The button is a direct join to 3.3 V. The big resistor to GND only lets about 0.3 mA through, so pin 0 stays at 3.3 V.
Find the mistake: Sam's doorbell sometimes rings when nobody has pressed it. Click the line where Sam's reasoning first goes wrong. line 2 Line 2: a pin joined to nothing isn't at 0 V. It floats, picking up electrical noise from nearby wires and your hand, and reads 0 or 1 at random. That is the doorbell ringing by itself.
Float: Remove the pull-down. Don't touch the button: watch pin 0 and the micro:bit.
Pin 0 reads 0 or 1 at random and the heart flickers: the pin is floating.
Pull it down: Put the pull-down back. Is the reading steady again?
A steady 0 until you press. The pull-down gives the pin a definite voltage when the button is open.
A press counter: A game counts button presses with no pull-down. What will the score do? Go up by itself, as random 1s count as presses Each random 0 → 1 looks exactly like a press.
Pin to GND: Pin 1 is joined straight to GND. Digital read pin P1 gives… 0 Joined to 0 V, it reads 0.
A pull-up: Another way to wire it: the button joins pin 0 to GND, and a 10 kΩ pull-up joins pin 0 to 3V. What does pin 0 read while the button is held? 0 Held: joined to GND, reads 0. Up: the pull-up holds it at 1. The mirror image of a pull-down, and how many boards wire their buttons (Arduino's INPUT_PULLUP).
the doorbell program: Put the program in order so the micro:bit shows a heart while the button is held, and nothing otherwise. see the program below Forever: read pin P0; if it is 1 show the heart, else clear the screen.
forever
if digital read pin P0 = 1 then
show icon heart
else
clear screen
Solutions
One possible solution for each task. Other correct programs are fine.
Vary: no pull-down › Float
Open task: any program that does what the step asks.
Vary: no pull-down › Pull it down
Open task: any program that does what the step asks.
Vary: no pull-down › A press counter
Open task: any program that does what the step asks.
Stretch and support
Stretch: How could code ignore a reading that only lasts a moment, so a noisy pin doesn't count as a press?
Support: Two pictures side by side, held and up, with a highlighter for what pin 0 is joined to.
Exit ticket
Why does a button wired from 3V to a pin need a resistor from the pin to GND?
So the pin is held at 0 V (reads 0) when the button is up. Without it the pin floats and reads 0 or 1 at random.
What each step is for
press it: Committing to the reading while the button is held tests the new move: an input pin reports the voltage as 1 or 0, not the volts or a press count.
Try: hold and let go: Holding and letting go settles the prediction and shows both readings; the heart is the program acting on them.
Worked example: two paths to pin 0: Tracing what pin 0 is joined to in each state models the move: held, 3V wins through the button; up, the pull-down joins it to GND. Sam's 'nothing means 0' is planted after the method.
Vary: no pull-down: Taking the pull-down away shows Sam's mistake on the board: a floating pin reads at random. Putting it back shows what the resistor is for.
Build it in Tinkercad: Building the button circuit in Tinkercad with the same program checks the idea in a fuller simulator.
inputs: Reading pins from what they are joined to, including a pull-up (the mirror image), and the program that reacts.
the doorbell program: Putting the program in order connects the reading to an action: read the pin, decide, show.
Where it leads
Next: Sensors that vary (analog read gives a number, not just 0 or 1).
Arduino unit: the same idea as pinMode(pin, INPUT_PULLUP).