Teach Remote lab lessons

Teach lesson

Arduino Visual Robot (3/4): proximity without crashes

Students use proximity sensor readings in visual code to avoid crashes, test thresholds, and explain how sensor input changes robot behavior.

  • Arduino robot (visual)
  • 55 min
  • Lower secondary / early high school
  • English
  • Robotics · Embedded systems

Sign in with an educator account to prepare a class session. Students join with a class code.

Arduino robot (visual)
Arduino robot (visual) · Lab details

Learning Outcomes

  • Read proximity sensors before making a decision.

  • Choose a simple threshold from observations.

  • Program a safe reaction to a nearby obstacle.

Student activity preview

Activity Content

Preview only. In a class session, students can fill in responses and submit their work to the teacher.

1

Sense before deciding

8 min

A sensor measures something and returns a reading. The proximity count responds to reflected infrared light; it is not a distance in centimetres. Object surface, angle and position can affect it. Compare actual readings at safe positions before deciding whether a higher count reliably means nearer in your test.

A threshold is the cut-off number that separates "safe" from "too close". The program:

  1. Reads the sensors.
  2. Compares the reading with a threshold.
  3. Chooses a reaction.
  4. Observes whether the reaction was safe.

If a proximity reading increases when an object is closer, what does the condition reading >= 3 mean? Why should you observe readings before choosing a threshold?

2

Measure before reacting

20 min

Remote positioning: use the robot itself; you cannot move a physical object in the remote room. Select Only robots on 8-shaped circuits when uploading. Its white floor, black line and surrounding wall provide fixed references. First locate the robot’s front in the camera and check clear space. Add the button-controlled positioning scaffold below. Each new B press produces just one 100 ms forward pulse; release it before pressing again. A and C can use the same single-press pattern for left/right turns (−125,125 or 125,−125). Take a reading only after both motors stop. Never keep moving toward a wall to force a high reading; preserve a visible gap and report any positions you cannot safely sample.

[Button B as stepButton]  (Buttons)
[Setup Serial speed 9600]
Arduino run first:
  [Change two motors speed] Left: 0 Right: 0
Arduino loop forever:
  if [stepButton single press]:
    [Change two motors speed] Left: 125 Right: 125
    [wait] 100 milliseconds
    [Change two motors speed] Left: 0 Right: 0
  ... read sensors and show the value here ...
  [wait] 50 milliseconds

Use single press, not is pressed: it triggers once per new press, even if the button is held. Keep the separate Button B as stepButton configuration block in the workspace; select stepButton in the condition. The motor stop is inside the condition after the timed pulse. Test one press in clear space and watch for three seconds: it must remain stopped until a new press. If it does not move, do not lengthen the pulse blindly; check upload, button and available space.

The English editor labels the center/left count block center sensor detect on his left; select center and left in its two menus.

  1. After the positioning condition, add Read proximity sensors, print center sensor detect on his left, and wait 300 ms. Keep the same sensor side throughout. With motors stopped, sample three safe positions at different distances from the same wall; label them by their camera position, without inventing distances in centimetres. If serial is unavailable, build the stationary LED decision below now with trial threshold 3 and record LED on/off and that threshold instead of an invented number. Then choose a provisional threshold from the table. If readings do not distinguish positions, record that result and explain why calibration remains inconclusive.

  2. ```text

  3. [Read proximity sensors]

  4. if [center sensor detect on his left >= your chosen number]: [Set red led to HIGH] [Set blue led to LOW]

  5. else: [Set red led to LOW] [Set blue led to HIGH]

  6. [Change two motors speed] Left: 0 Right: 0

  7. ```

Observed situation Sensor used Reading (number, or where the LED reacts) Should it react? Notes

Choose a provisional warning threshold using two observations. If they do not distinguish positions, say why the threshold is not yet justified and name the next safe test.

3

Program a safe reaction

18 min

Build a stationary proximity warning using your calibrated threshold. The positioning condition is the only place allowed to move the robot. Both branches of this warning leave the motors stopped. Test a farther and a nearer safe position; state whether the LED distinguishes them. A threshold that does not separate the observations is an inconclusive calibration, not proof of safe autonomous driving.

[Read proximity sensors]
if [center sensor detect on his left >= your chosen number]:
  [Set red led to HIGH]
  [Set blue led to LOW]
else:
  [Set red led to LOW]
  [Set blue led to HIGH]
[Change two motors speed] Left: 0 Right: 0

Did the reaction happen too early, too late, or at the right time? State what you would adjust: threshold, speed, or wait time.

Describe one limitation of the sensor or your test: object position, unstable reading, robot position, queue time, or camera view.

4

Evidence submission

9 min

Proximity reaction program

Submit your threshold, a screenshot or description of the program, and one observation from a test where the robot reacted or should have reacted.

Turn this preview into a live class session

Continue to LabsLand Teach to use this lesson with your students and review the access available to your account.