Arduino Learning Studiorobotics pathway

R13-U2 · usually age 13 · Robotics Engineers

Read and React to Obstacles

What should the robot do when it senses danger?

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

Build: Distance-aware rover

The distance sensor goes on the rover, and the rover learns when to stop: readings measured from its front, a stop distance with a margin for the ground covered between readings and while braking, no echo treated as no reading, stray echoes, a log of every reading, and repeatable trials.

  • Sense
  • Decide

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

After R13-U1 to U3, start the Arduino Rescue Rover course at session 10; sessions 5–9 become a quick review. Open the course →

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 · 75 min

    Where should the sensor sit on the rover?

    Mounting the HC-SR04 at the front, level, with nothing in front of its two transducers; distance from the sensor's face vs from the rover's front edge (an offset); how wide it sees one box, found by experiment.

    In the studio

    Hands-on

    In Read a sensor, set the sensor 3 cm behind the ruler's zero and see what happens to every reading. On the rover, with the motor battery switched off and unplugged and USB unplugged, mount the sensor at the front and wire it as the guide says (VCC 5V, GND, Trig D9, Echo D10). Upload Read a sensor's sketch and print the distance. With a box straight ahead, compare the reading with a ruler from the rover's front edge at three distances, and work out the offset. Then slide the box sideways at 40 cm until it is no longer seen, and mark that edge on both sides.

    Starting code: Read a sensor's sketch (Copy code in the lab's code panel): it reads with pulseIn(echoPin, HIGH, 30000) and prints the distance, or “no echo” for 0.

    Pins

    D9
    HC-SR04 Trig
    D10
    HC-SR04 Echo

    Evidence to collect

    The offset worked out from three readings, and a floor sketch of where the rover sees this box at 40 cm (both edges marked; a smaller or angled box gives other edges).

    Predict
    Will the reading be more or less than the ruler measured from the rover's front edge?
    Debug
    If every reading is “no echo”, unplug USB and check Trig and Echo against the guide.
    Reflect
    Where in front of the rover would a box be missed?

    ⚠ Adult checks before power-on: Sensor VCC to 5V and GND to GND, not reversed, before USB goes in; Trig on D9 and Echo on D10, with no other part on those pins. The motor battery's power-off switch is off and its holder unplugged: no motor turns in this session. No wire is moved, pulled or plugged in while anything is powered: power-off switch off and battery unplugged first, then USB.

    Works towards: Stop rules

  2. Session 2 · 90 min

    How far before the box must the rover decide to stop?

    The stop rule and its margin: the rover keeps moving between two readings (at least 60 ms apart) and while it brakes, so it decides at stopCm and comes to rest nearer. Brake with the driver's short brake.

    Hands-on

    In Build a project, run the five trials at speed 128 and at 255 with the same stopCm, and compare where the model rover comes to rest (255 stays in the model). On the rover, start from your R13-U1 session 5 sketch and paste in the reading lines from Read a sensor's sketch: read, and if the reading is real and under stopCm, brake; otherwise drive forward. Upload and test it lifted first, wheels in the air, with a box moved by hand. Then on the floor drive at a box three times at the lowest value that starts both wheels and measure where it comes to rest; repeat at a higher value, never above 160 of 255. Choose a stopCm that leaves at least your margin (say 15 cm) in every run.

    Starting code: The learner's own sketch from R13-U1 session 5, plus the reading lines from Read a sensor's sketch (Copy code in the lab's code panel).

    Evidence to collect

    A rest-distance table (speed × stopCm × three runs), the chosen stopCm and margin, and a sentence on why the faster rover rests nearer.

    Predict
    How much nearer than stopCm will the rover rest at each speed?
    Debug
    If it never brakes, print each reading to the Serial Monitor before changing the rule.
    Reflect
    Why does the faster rover need a bigger stopCm?

    ⚠ Adult checks before power-on: The motor battery reaches the driver's VM only, through its power-off switch; the board's 5V goes to the driver's VCC only; every GND is joined. Lifted for the first run; then on the floor at the lowest value that starts both wheels, never above 160 of 255, the power-off switch in reach, a soft box and a clear area. Lift the rover (wheels in the air) before switching the motor battery back on: the sketch keeps running on USB, so the wheels take its last command at once.

    Works towards: Stop rules

  3. Session 3 · 90 min

    What should the rover do when there is no echo?

    With pulseIn(echoPin, HIGH, 30000), as in Read a sensor, no echo gives 0. pulseIn()'s default timeout is one second, and with no echo the sensor's Echo pin stays HIGH for 38 ms (datasheet version 2). In the UNO's core, one loop budget covers both the wait for the pulse and the pulse itself, so a 38 ms pulse never fits in 30000 µs and pulseIn() gives 0; with the default timeout it would return about 38000 µs, read as about 655 cm. That 0 is no reading, not 0 cm. Then: one stray close reading; two close readings in a row; and silence, a run of 0s that may mean a loose sensor.

    In the studio

    Hands-on

    In Read a sensor, try the rover's stop rule in Apply: does 0 count as close, or is it skipped? One close reading, or two? Find the rule that passes all three runs, including open space, where it must never stop. On the rover, lifted with its wheels in the air, upload your session 2 sketch, point the sensor at open space and at a soft cushion, and print each reading. Change the rule: skip a 0, and brake only after two close readings in a row. Then try a silence rule: brake and wait after one second with no reading. It catches a loose sensor, but it also stops the rover in open space, which the Apply rule never does: keep it only for a course with walls always in range. To fake a loose sensor, switch the motor battery off, unplug it and USB, and take out the Trig wire (never the Echo wire: a floating D10 can read HIGH or LOW at random). Then plug USB in again and watch: with no trigger the sensor never starts a reading, Echo stays LOW, and every pulseIn() gives 0 after its timeout.

    Starting code: The learner's session 2 sketch.

    Pins

    D9
    HC-SR04 Trig
    D10
    HC-SR04 Echo

    Evidence to collect

    A decision table: a sequence of readings (real, 0, one stray close one, a second of 0s in open space, Trig out) → what each rule did and what it should do, checked on the lifted rover, with the silence rule's open-space trade-off written down.

    Predict
    Before each test, predict what the rule should do: box, open space, cushion, Trig out.
    Debug
    If it brakes in open space within a second, print the readings: a 0 counted as close is the fault. After a full second of 0s, braking is the silence rule at work.
    Reflect
    When is stopping on silence worth also stopping in open space?

    ⚠ Adult checks before power-on: The motor battery reaches the driver's VM only, through its power-off switch; the board's 5V goes to the driver's VCC only; every GND is joined. No wire is moved, pulled or plugged in while anything is powered: power-off switch off and battery unplugged first, then USB. The motor battery stays off and unplugged while the Trig wire is out; lifted, wheels in the air, for every test in this session. Lift the rover (wheels in the air) before switching the motor battery back on: the sketch keeps running on USB, so the wheels take its last command at once.

    Works towards: Stop rules

  4. Session 4 · 75 min

    What did the rover see just before it stopped?

    Logging: one Serial.println() per reading, with the time from millis() and the decision, while the rover stays on its USB tether; reading the log against what was seen.

    Hands-on

    In Build a project, look at how the sketch prints one line per reading and what the Serial Monitor shows. Start from your session 3 sketch and print each reading as one line: the time from millis(), the distance (or “no reading”) and the decision. Upload, then open the Serial Monitor before the motor battery goes on (opening it restarts the UNO). With the USB cable held by the adult, drive at a box on the floor. Find in the log the reading that made it brake, and work out how far the rover went after it.

    Starting code: The learner's session 3 sketch.

    Evidence to collect

    A short log copied from the Serial Monitor, annotated: the braking reading, the readings before it, and any 0 or stray reading and what the rule did with it.

    Predict
    How many readings come between “far” and the brake?
    Debug
    If the Serial Monitor shows nothing readable, check its baud rate against Serial.begin() in the sketch.
    Reflect
    What does the log show that watching the rover did not?

    ⚠ Adult checks before power-on: The motor battery reaches the driver's VM only, through its power-off switch; the board's 5V goes to the driver's VCC only; every GND is joined. The USB cable is held clear of the wheels by the adult; on the floor at the lowest value that starts both wheels, never above 160 of 255; the power-off switch in reach. Lift the rover (wheels in the air) before switching the motor battery back on: the sketch keeps running on USB, so the wheels take its last command at once.

    Works towards: Stop rules

  5. Session 5 · 90 min

    Does it stop every time?

    Repeatable trials: the same start line, speed and box each time, varied on purpose (two distances, a box at an angle, a soft target); every trial logged; a trial that rests inside the margin is a failure, even once.

    In the studio

    No studio lab: this session is off-screen.

    Hands-on

    Start from your session 4 sketch and do not change it during the trials. Mark a start line and two box positions with tape. Run five trials at each position, the same way each time, logged. Add one trial with the box at an angle and one with a cushion: twelve trials in all. Record where it rests each time, and write down any failure and what the log showed.

    Starting code: The learner's session 4 sketch, unchanged during the trials.

    Evidence to collect

    The unit's evidence: repeatable stop decisions with logged readings. A trial table of the ten straight-on trials and the two harder cases (rest distance, pass or fail): a trial passes only if the rover rests at least the chosen margin from the box, and the unit passes only when all twelve pass. The log of any failure.

    Predict
    How many of the twelve trials will rest outside your margin?
    Debug
    For a failure, find the reading in the log that came too late or was missing.
    Reflect
    Is the stop decision repeatable, and what one change would you test next?

    ⚠ Adult checks before power-on: The motor battery reaches the driver's VM only, through its power-off switch; the board's 5V goes to the driver's VCC only; every GND is joined. The power-off switch tested before the first trial; on the floor at the lowest value that starts both wheels, never above 160 of 255; the course clear of people's feet and anything fragile. Lift the rover (wheels in the air) before switching the motor battery back on: the sketch keeps running on USB, so the wheels take its last command at once.

    Works towards: Stop rules

Materials

  • The rover from R13-U1 (Uno, TB6612FNG, two gear motors; motor battery: 4 × AA alkaline cells (1.5 V each, about 6 V fresh) in a holder whose on/off switch is the power-off switch)
  • HC-SR04 ultrasonic sensor with a front mount (card, tape or a bracket)
  • Cardboard boxes, a cushion, masking tape and a tape measure or ruler
  • A computer with the Arduino IDE and a long USB cable for the tether

⚠ Safety before any session

  • Switch off and disconnect the motor battery before changing any wire, including the sensor's, then unplug USB.
  • Motors run from their own battery through the driver, never from a pin; every GND is joined.
  • Wheels lifted for the first run of every new rule; then on the floor at the lowest value that starts both wheels, never above 160 of 255.
  • Lift the rover (wheels in the air) before switching the motor battery back on: the sketch keeps running on USB, so the wheels take its last command at once.
  • Soft boxes only; the course is clear of feet; the adult keeps the USB tether away from the wheels.
  • Motor battery: AA alkaline cells only; no NiMH, Li-ion, LiPo, RC packs or 18650 cells.
  • If anything gets warm: switch off or unplug at the holder, don't touch it, tell the adult.

Notes for the adult

  • Leads into the Rescue Rover course (R13-U4): course sessions 5 and 6 measure distance and warn on the bench; this unit puts the sensor on the moving rover and makes the stop decision repeatable, which the course's session 9 builds on.
  • A margin is the point: ask learners to say what the rover does between the reading that says close and the moment it rests.
  • Each session lists a line to predict before power-on, a first check when it goes wrong, and a question to reflect on before tidying up.
  • Before the first upload, test an upload on each computer (Blink, with its own board and cable), so the session starts on time.
  • Learners who are ready can start here at any age once they can drive the rover from code (R13-U1) and handle noisy readings (R12-U3).
  • The labs are preparation in a model; the trials on the floor are the evidence.

Planned studio features

Not built yet. The unit runs without them.

  • A stop-distance worksheet: speed, reading interval and the learner's measured rest distances → the stopCm needed for a chosen margin.
  • A trial log for unit plans (the notebook's trial log is only for the Rescue Rover course).
  • A view of where the sensor sees: a box moved sideways in front of a rover in the studio.

Sources

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