Arduino Learning Studiorobotics pathway

R12-U3 · usually age 12 · Robotics Engineers

Sensors and Actuators

How do measurements cause actions?

Pilot unit plan · 6 sessions · not yet classroom-validated

Build: Distance-alert or night-light system

Measurements that cause actions: a voltage divider read with analogRead(), scaled with map(), and used to set a brightness with PWM; a light sensor with a threshold; an ultrasonic distance with its no-echo case; an alert with tone(); and a servo pointer. Real readings are noisy, and the plan handles that on purpose.

  • Sense
  • Decide
  • Act

Who it is for

Age is a starting point, never a limit. A learner who can show what this unit starts from can begin here at any age.

How they learn
By reading and changing real Arduino sketches, predicting, testing in a model, then building and testing the real circuit.
The adult's role
An adult checks every circuit and anything that moves before it is powered.
Session
75–90 minutes
Hardware
Arduino Uno R3 or compatible (5 V). The adult checks the power circuit and the motor driver. Motors never run from a pin; share GND between supplies.

Starts from

Builds, and what it is the input for

In the studio today

The labs run a model of each sketch in the browser. They prepare the real build; they never count as a working circuit.

Sessions

  1. Session 1 · 90 min

    How does turning a knob become a number?

    The potentiometer as a voltage divider; analogRead() gives 0 to 1023 for 0 V to 5 V; a floating analog pin.

    In the studio

    Hands-on

    In Turn a knob, predict the reading at three knob positions, then test. On the bench, with USB unplugged, wire the potentiometer's outer legs to the 5V and GND rails and its middle leg to A0. Print analogRead(A0) and, at three positions, measure the middle leg's breadboard row to the GND rail on DC volts. Then unplug USB, move the A0 wire to an empty row, plug USB back in and watch the reading wander.

    Starting code: Analog Read Serial, from File/Examples/01.Basics/AnalogReadSerial: it prints analogRead(A0).

    Pins

    A0
    potentiometer middle leg (then a loose wire, for the floating test)

    Evidence to collect

    A table for three knob positions: measured volts, the printed reading, and the reading × 4.9 mV compared with the meter. A note on the floating reading.

    Predict
    Predict the reading at the knob's two ends and its middle before you turn it.
    Debug
    If the reading sticks at 0 or 1023, unplug USB and check that the middle leg, not an outer leg, goes to A0.
    Reflect
    Why does a pin that is joined to nothing still give a number?

    ⚠ Adult checks before power-on: USB unplugged while wiring and while moving the A0 wire; only the outer legs go to 5V and GND; the middle leg goes to A0. For the volts readings: red lead in the V/Ω socket, never 10A; probes go on breadboard rows or rails, not at the header pins.

    Works towards: Analog readings in code, Noise and timeouts

  2. Session 2 · 75 min

    How can one number set a brightness?

    map() from 0–1023 to 0–255 (integer maths, remainders cut off); analogWrite() and PWM on the ~ pins 3, 5, 6, 9, 10 and 11: the pin is fully on for part of each cycle.

    In the studio

    Hands-on

    With USB unplugged, add an LED with its 220 Ω resistor on D9. Map the knob to 0–255 and write it with analogWrite(9, …). Work out map() by hand for three readings and check against the printed values. Then, with USB unplugged, move the LED to D8 (not a ~ pin), predict, test, and with USB unplugged again move it back.

    Starting code: Analog In, Out Serial, from File/Examples/03.Analog/AnalogInOutSerial: it reads A0, maps it and writes the LED on pin 9.

    Pins

    A0
    potentiometer middle leg
    D9
    LED through its 220 Ω resistor
    D8
    the same LED, moved for one test

    Evidence to collect

    Three input cases: the reading, the mapped value worked by hand and printed, and what the LED did. A sentence on what happened on D8 and why.

    Predict
    Predict the mapped value for a reading of 512 before the board prints it.
    Debug
    If the LED only snaps on and off, check that its pin has a ~ beside it on the board.
    Reflect
    What did the integer maths in map() cost you, and does it matter for an LED?

    ⚠ Adult checks before power-on: The LED has its resistor; the potentiometer is wired as in session 1; USB unplugged while moving the LED.

    Works towards: PWM in code, Analog readings in code

  3. Session 3 · 90 min

    How does a robot notice the dark?

    A light-dependent resistor (LDR) in a divider with a 10 kΩ resistor; calibrating a threshold for the room; noise near the threshold and hysteresis (two thresholds).

    In the studio

    Hands-on

    In Sense light, find the threshold that switches cleanly. On the bench, with USB unplugged, take the potentiometer out, wire the LDR from 5V to A0 and 10 kΩ from A0 to GND, and move the LED to D13 for the night-light. Print readings in room light, in shadow and covered. Choose a threshold. Hold a hand slowly over it and count flickers; then add a second threshold so it switches on and off at different readings, and count again.

    Starting code: Sense light's sketch (Copy code in the lab's code panel): the LDR on A0 and the lamp on pin 13.

    Pins

    A0
    LDR divider (LDR to 5V, 10 kΩ to GND)
    D13
    night-light LED

    Evidence to collect

    Readings for three light conditions, the chosen threshold(s), and the flicker count before and after hysteresis.

    Predict
    Predict the readings in room light, in shadow and covered, and which is highest.
    Debug
    If the LED flickers at dusk, print the readings near the threshold and look for them crossing it back and forth.
    Reflect
    How far apart should the two thresholds be, and how did you decide?

    ⚠ Adult checks before power-on: USB unplugged while wiring; the 10 kΩ resistor goes from A0 to GND; the LED has its resistor.

    Works towards: Analog readings in code, Noise and timeouts

  4. Session 4 · 90 min

    How far away is it, and what if there is no echo?

    The HC-SR04: a 10 µs trigger pulse, an echo time read with pulseIn(), microseconds ÷ 58 = centimetres. With no echo, version 2 of the datasheet says Echo stays HIGH for 38 ms, so the default one-second timeout would time that as a distance; pulseIn(echoPin, HIGH, 30000) gives up after 30,000 µs and returns 0, which means no reading, not 0 cm.

    In the studio

    Hands-on

    In Read a sensor, predict a distance from an echo time, then test. On the bench, with USB unplugged, take the LDR divider and the LED out and wire the sensor (VCC 5V, GND, Trig D9, Echo D10), and print the distance. Compare five distances with a ruler against a flat box. Then try a soft or angled target until there is no echo, and check that the sketch prints “no echo” (no reading) for 0 instead of a distance.

    Starting code: Read a sensor's sketch (Copy code in the lab's code panel): it uses delayMicroseconds() for the 10 µs trigger pulse and pulseIn(echoPin, HIGH, 30000), and prints “no echo” for 0.

    Pins

    D9
    HC-SR04 Trig
    D10
    HC-SR04 Echo

    Evidence to collect

    At least five ruler-versus-sensor comparisons and one no-echo case, recorded as no reading.

    Predict
    Predict the echo time for a box 20 cm away, then compare with the reading.
    Debug
    If every reading is 0, check that Trig and Echo are not swapped and that the timeout is 30000, then unplug USB before moving a wire.
    Reflect
    Why is printing “no echo” safer for a robot than printing a distance of 0, or about 655 cm?

    ⚠ Adult checks before power-on: USB unplugged while wiring; sensor VCC to 5V and GND to GND, not reversed, before USB goes in.

    Works towards: Noise and timeouts

  5. Session 5 · 75 min

    How can the system warn us?

    tone() and noTone() on a passive piezo buzzer, never a speaker straight on a pin; a distance threshold that starts an alert; silence for no reading; tone() and PWM on pins 3 and 11.

    Hands-on

    In Make a sound, find the pitch and the pattern you want. On the bench, with USB unplugged, add a passive piezo on D8 to the distance circuit: beep when nearer than a chosen distance, stay quiet when far, and stay quiet with no reading. Test far, near and no echo.

    Starting code: The learner's session 4 sketch, plus the tone() and noTone() lines from Make a sound's sketch (Copy code in the lab's code panel; its buzzer is on pin 8).

    Pins

    D9
    HC-SR04 Trig
    D10
    HC-SR04 Echo
    D8
    passive piezo

    Evidence to collect

    Three input cases (far, near, no reading): the reading, the decision and the sound heard.

    Predict
    Predict what the alert does when the sensor gets no echo, before you test it.
    Debug
    If it beeps with nothing near, print the distance with each decision and look for the 0 being treated as near.
    Reflect
    Who would the alert annoy, and how could you make it less annoying but still safe?

    ⚠ Adult checks before power-on: USB unplugged while adding the piezo. A passive piezo buzzer on the pin, its other leg to GND. No speaker straight on a pin; a magnetic buzzer needs a transistor driver and a flyback diode, never a pin.

    Works towards: Noise and timeouts

  6. Session 6 · 90 min

    How do measurements cause movement?

    The Servo library: write() sets a standard servo's angle; map() from a distance to 0–180. A servo draws more current when it moves, so it gets its own supply. On the Uno the library stops PWM (analogWrite()) on pins 9 and 10, so the dimmed LED goes on D5.

    In the studio

    Hands-on

    With all power unplugged (USB and the servo supply), add the servo: red wire to the servo supply's +, brown or black wire to its −, the supply's − joined to the Arduino GND rail, and the signal wire to D7. Add an LED with its 220 Ω resistor on D5. Map the distance to a pointer angle on the servo and to the LED's brightness with analogWrite(5, …); with no reading, hold the angle and turn the LED off. Keep session 5's alert on D8. Test far, near and no echo.

    Starting code: The learner's session 5 sketch, plus the Servo lines from Sweep a servo's sketch (Copy code in the lab's code panel), with the servo's pin changed to 7.

    Pins

    D9
    HC-SR04 Trig
    D10
    HC-SR04 Echo
    D8
    passive piezo
    D7
    servo signal
    D5
    LED through its 220 Ω resistor

    Evidence to collect

    The unit's evidence: recorded observed behaviour of the distance alert for three input cases (far, near, no echo: input, reading, decision, output) and how the sketch handles a noisy or missing reading.

    Predict
    In Sweep a servo, predict how long the pointer needs to cross 0–180, then test it there before the bench.
    Debug
    If the board resets (setup() runs again) or the power light flickers when the servo moves, its supply is dipping, a brown-out: a computer's USB port usually gives only 500 mA, so check the servo's own supply and the shared GND.
    Reflect
    Which of your three cases was hardest to make reliable, and what in the sketch handles it?

    ⚠ Adult checks before power-on: All power unplugged while wiring. The servo runs from its own supply, a 4×AA NiMH holder (4.8 V) with an on/off switch, measured within the servo's 4.8 - 6 V: not the 7–12 V holder, not the board's 5V pin, no 18650 Li-ion cells. Supply − joined to the Arduino GND; signal on D7; fingers clear of the horn.

    Works towards: PWM in code, Noise and timeouts

Materials

  • Per pair: Arduino Uno R3 (or compatible), its USB cable, a computer with the Arduino IDE, breadboard and jumper wires
  • 10 kΩ potentiometer; LDR and a 10 kΩ resistor; LEDs with 220 Ω resistors
  • HC-SR04 ultrasonic sensor, a ruler and a flat box
  • Passive piezo buzzer (not an 8 Ω speaker)
  • Micro servo rated 4.8 - 6 V, with its own supply: a 4×AA NiMH holder (4.8 V) with an on/off switch; no 18650 or other Li-ion cells
  • A digital multimeter (DC volts)

⚠ Safety before any session

  • Unplug USB and the servo supply before changing a wire; every LED has its resistor.
  • The potentiometer's middle leg never goes to 5V or GND.
  • Passive piezo only on a pin. No speaker straight on a pin; a magnetic buzzer needs a driver.
  • The servo has its own 4×AA NiMH supply with GND shared, never the board's 5V; fingers clear of the horn.
  • If anything gets warm: switch off or unplug at the holder, don't touch it, tell the adult.

Notes for the adult

  • Before the first upload, test an upload on each computer (Blink, with its own board and cable), so the session starts on time.
  • Noise is the lesson, not a fault: ask learners to show a jumpy reading and how their sketch copes.
  • Each lab is preparation in a model; the bench readings are the evidence.
  • Check each NiMH holder with the meter before session 6: it must read within the servo's 4.8 - 6 V.
  • Learners who finish early can try smoothing: averaging several readings before deciding.

Planned studio features

Not built yet. The unit runs without them.

  • A plotter for the learner's own logged readings, kept in the browser only.
  • Notebook pages for unit plans (today the notebook holds only the Rescue Rover course).

Sources

The facts this plan relies on, in each source's own words.