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