- :-

Topics Covered

  • Ultrasonic Sensor
  • Thresholds
  • Forward Until Behavior
  • Lesson Links

    Check Your Understanding:
    1. 1. What does the Wait Block wait for before playing the "Hello" sound?
    2. The Ultrasonic Sensor to detect an object less than 50 cm away
      The Ultrasonic Sensor to detect an object more than 50 cm away
      The robot to travel less than 50 cm
      The Ultrasonic Sensor's reading to change by up to 50 cm
    3. 2. How do you select the sound file the robot plays?
    4. By clicking in the upper-right "File Name" blank on the block
      By speaking into the speakers of the EV3
      By adding a File Block
    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.

    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.

    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!

    Pause for a couple of seconds after commands for consistency.

    + hint
    Try It!
    Try it! 1

    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).

    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?

    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!

    Did You Know?

    Did you know?

    How the Ultrasonic Sensor Works

    The Ultrasonic Sensor uses the speed that sound waves travels to measure distance to an object.
    The sensor has two openings on its front; one opening emits ultrasonic waves, while the other
    receives them. The Ultrasonic Sensor measures distance by timing how long it takes for an ultrasonic
    wave sent out by the emitter to bounce off an object and come back to the receiver.

    Try It!
    Try it! 2

    Sound Sentences

    You can have multiple sounds play one after another to form sentences. Try adding a second Sound Block to your program so it says "Object Detected" instead of just "Hello"!

    "Object" and "Detected" can be found as separate sound files in the "Information" folder. How would you get the EV3 to say them one after another?

    What happens?

    Place the Sound Block one after another makes them run and therefore play their sounds - in order.

    Try it! 3

    Sensor Change Mode

    In addition to "Comparing" the value of the sensor against the Threshold, the Wait Block can also look at the amount the sensor value has changed since the command started.

    • Place an object in front of the Ultrasonic Sensor.
    • Change the Mode of the Wait Block to Ultrasonic Sensor - Change - Distance Centimeters.
    • Set the direction setting to "Any" (2)
    • Set the Amount setting to "5"
    • Run program, then move object 5cm closer to or further away from Ultrasonic Sensor

    What happens?

    The Wait Block ends and the alarm sounds whenever the Ultrasonic Sensor's value has changed by more than 5 centimeters from the time it started Waiting.