Exercice : Mini Challenge

Mini Challenge 1: Threshold Value

The Wait - Ultrasonic Sensor Block uses a "Threshold" to define what it is waiting for.

Rather than look for a specific value (like 1cm or 200cm), it sets a "cutoff" value that divides all the possible Ultrasonic Sensor values into two categories:

  • If the distance value is above the Threshold, it is considered "Far"

  • If the distance value is below the Threshold, it is considered "Near"

This way, the Wait Block does not have to worry about the difference between an object at 29cm and an object at 30cm; it only has to worry about about whether the value is above or below the Threshold.

Question

Change the Wait Block's Threshold value so that the alarm only sounds if someone passes within 10cm of the sensor, then change it again so that it will go off if anyone comes within 100cm of the sensor.

Indice

Hint 1: In both cases, the Wait Block will simply "wait for" a value below the Threshold - you just need to change what that cutoff distance is.

Indice

Hint 2: Pause for a couple of seconds after commands for consistency.

Mini Challenge 2: Missing Object Alarm (Wait for Far)

What does the Wait Block do if you set it to wait for a value Greater Than the Threshold instead of Less Than? Change the Wait Block's "Compare Type" setting to Greater Than (2).

Question

Place an object in front of the robot, and download and run the program. Now, try moving the object and see what happens.

What happens?

Solution

The Wait Block is waiting for an Ultrasonic Value "Greater Than" the Threshold before playing the sound. When the object is removed, the Ultrasonic Sensor's value jumps up because the closest object it can see is now the wall. Since the wall is more than ("greater than") 50 cm away, the Wait Block stops waiting, and the Sound Block plays.