← Teacher guide

Same circuit, new board

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.

Arduino · A new board · about 40 minutes · Open the student lesson

Classroom resources

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.

Students will be able to

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

  1. Predict: ask students to point at the pin number in each line of the sketch.
  2. Find the mistake: the dim glow is a real effect students will see on hardware; name it the pull-up.
  3. 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 seeA question to askThe 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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

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.

Sources