Students read the robot's distance sensor inside forever and stop before an obstacle, then build a parking robot that slows down as things get closer.
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.
Predict and Run 8 min · Investigate 10 min · Modify 8 min · Make 12 min · Real robot 7 min (optional)
The robot's distance sensor (ultrasonic) times an echo and reports how far away the nearest object is, in centimetres, up to 40. With nothing in range it reports 40. In blocks this is robot obstacle distance (cm), in the Robot drawer. The idea is the same as the micro:bit sensors lessons: a sensor is a number the world keeps changing, so the program must read it again in forever to follow it. Here the stakes are visible: read it once and the robot crashes.
Every program starts with a block that picks the robot (Elecfreaks Cutebot here). Schools with another supported robot (DFRobot Maqueen, Yahboom Tiny:bit and others in the robot extension) change only that block; everything else is the same. robot motor tank sets the left and right wheel speeds (−100 to 100).
The simulator has one arena: a looping line and some boxes. Students drag the boxes and the robot with the mouse. The robot does not stop instantly: it slows over a short distance, like a car, which is why the stop distance is 15 cm, not 1.
The robot only knows the distance when the program reads it, many times a second. Ask where the sensor is read and how often.
| What you will see | A question to ask | The fix |
|---|---|---|
| The robot drives straight off without stopping. | Is there a box in front of it? Can you see the blue beam touch the box? | Drag a box into its path, or turn the robot to face one. |
| The robot never moves. | Is robot motor tank there, and are both numbers above 0? | Add robot motor tank 50 50 (in on start for the Predict program, or inside the else for the parking robot). |
| The parking robot never stops. | Which question does your if ask first? | Ask about the closest distance (less than 10) first: the first true question wins. |
| The real robot stops in a different place from the simulator. | What is different about the real floor and batteries? | Normal: real robots coast and their sensors are noisy. Change the numbers until it works on your floor. |
One possible solution for each task. Other correct programs are fine.

robot.elecfreaksCuteBot.start()
robot.motorTank(50, 50)
basic.forever(function () {
if (robot.obstacleDistance() < 25) {
robot.motorStop()
}
})

robot.elecfreaksCuteBot.start()
robot.motorTank(50, 50)
basic.forever(function () {
if (robot.obstacleDistance() < 15) {
robot.motorStop()
basic.showIcon(IconNames.No)
}
})

robot.elecfreaksCuteBot.start()
basic.forever(function () {
if (robot.obstacleDistance() < 10) {
robot.motorStop()
} else if (robot.obstacleDistance() < 30) {
robot.motorTank(20, 20)
} else {
robot.motorTank(50, 50)
}
})
Stretch: Make a 'nervous' robot: when something comes closer than 10 cm, it reverses (robot motor tank −30 −30) for half a second, then stops.
Support: Give the parking robot's if / else if / else blocks with the numbers filled in, and ask students to drag in the right motor block for each part.
Why does Mia's robot crash when the if is not inside forever?
It checks the distance once, at the start, when the box is still far away. It never checks again, so it never stops.
Next: instead of stopping, turn away and keep exploring, like a robot vacuum. Real-world links for discussion: parking sensors, automatic doors, warehouse robots that slow down near people.