Students run a blink sketch whose pin number doesn't match the wiring, fix every pin number, see the dim pull-up glow of a missing pinMode, build the circuit on an Uno in Tinkercad blocks and read the C++ beside them, then write a short sketch for a new pin.
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 match the pin numbers in a sketch to the wiring.
I can set a pin as an output and switch it on and off.
I can find the C++ behind Tinkercad's blocks.
Timing
Predict and Try 6 min · Worked example 8 min · Vary 5 min · Tinkercad 12 min · Practise and Make 9 min
Before class
The board in the lesson runs a subset of Arduino C++ against a model of an Uno (5 V pins, an LED and resistor per pin, simulated time). It behaves like the real board for the things these lessons teach: a missing ; stops the upload, a pin written HIGH without pinMode glows dimly (the internal pull-up), = in an if assigns. It is not a full compiler; real hardware comes in the next unit.
Tinkercad: Arduino Uno R3 is in the components list; Code › Blocks + Text shows the generated C++ beside the blocks (it can't be edited until you switch to Text). Same class code as the micro:bit unit.
Running the lesson
Predict: ask students to point at the pin number in each line of the sketch.
Find the mistake: the dim glow is a real effect students will see on hardware; name it the pull-up.
Tinkercad: ask which block made which line of C++.
The hard part (on purpose)
C++ looks dense after blocks. Read it aloud line by line and point at the pin number in each.
When students get stuck
What you will see
A question to ask
The fix
A student changes only pinMode.
Which pin does each digitalWrite line switch?
Every line that names a pin.
Upload fails with a ; error.
Which line does the message name, and how does it end?
Every statement ends with ;
Answers to the checks
which pin?: The LED (with its resistor) is wired to pin 12. The sketch above uses pin 13. When it runs, the LED… It stays dark. Pin 13 blinks, but nothing is wired to it. The LED is on pin 12, which the code never switches.
Try: run it: Upload and run the sketch. What does the LED on pin 12 do?
Nothing: the sketch switches pin 13, and the LED is on pin 12.
Every pin number: Which lines must change so the sketch blinks the LED on pin 12? All three: pinMode and both digitalWrite lines Every line that names a pin must name 12: setting it up, switching it on and switching it off.
Find the mistake: Sam's LED is on pin 13. It doesn't blink: it just glows very dimly now and then. Click the line where Sam's sketch goes wrong. line 2 Line 2: pin 13 was never set as an OUTPUT (pin 12 was). Writing HIGH to a pin that is still an input only switches on its weak pull-up, so the LED glows dimly instead of lighting.
Vary: change the pin: Change the sketch so the LED on pin 12 blinks. Upload and run it.
With 12 in all three lines, pin 12 is an output and switches on and off.
Set up a pin: A buzzer is wired to pin 8. Which line sets it up? pinMode(8, OUTPUT); pinMode(pin, mode): pin 8, as an OUTPUT.
A dim glow: An LED glows very dimly instead of lighting, and the pin numbers all match. What is the most likely cause? The pin was never set with pinMode(pin, OUTPUT) HIGH on a pin left as an input only turns on its weak pull-up: a faint glow.
your own sketch: The LED is wired to pin 7. Write the sketch to switch it on (and keep it on).
pinMode(7, OUTPUT) in setup(), digitalWrite(7, HIGH) in loop().
Solutions
One possible solution for each task. Other correct programs are fine.
Vary: change the pin
Open task: any program that does what the step asks.
your own sketch
Open task: any program that does what the step asks.
Stretch and support
Stretch: Wire a second LED on pin 9 and blink them in turn.
Support: A printed sketch with the pin numbers highlighted.
Exit ticket
An LED is wired to pin 4. Write the two lines that set it up and switch it on.
pinMode(4, OUTPUT); (in setup) and digitalWrite(4, HIGH); (in loop).
What each step is for
which pin?: Committing to what happens when the code names a different pin from the wire tests the new move: pin numbers in code must match the wiring. The wrong options are the 'code works whatever pin' picture.
Try: run it: Running the sketch settles the prediction: the board shows pin 13 not wired, and the LED on pin 12 never changes.
Worked example: read the pins: Reading each line for its pin number models the move: every pin number must be the wired pin. Sam's half-changed sketch is planted after the method, with its real symptom (a dim glow from the pull-up).
Vary: change the pin: Changing every pin number in the code, then running it, applies the move directly.
Build it in Tinkercad: Building the circuit on an Uno in Tinkercad with blocks, then opening the Blocks + Text view, shows that the blocks are this C++.
pins: Reading pin numbers and modes in short sketches, with the pull-up glow as the symptom of a missing pinMode.
your own sketch: Writing pinMode and digitalWrite from scratch for a new pin puts the lesson's two lines together without a model to copy.
Where it leads
Next: Reading the C++ (what setup() and loop() do, and timing with delay).
Circuits with the micro:bit: the same loop and resistor ideas.