If the if portion of the loop block isn’t true, then the else if portion enables you to
test for a different condition. If this condition is met, then the blocks within the do
section under the else if section will run. In this instance, if there is an object closer
than 10 cm to the Ultrasonic Sensor, the red LED on the PULSE controller will be lit.
Experiment with the Ultrasonic Sensor with different objects and different heights
to see how the sensor reacts.
Extension Activity
With the example as a reference, try creating a new sketch to use your Ultrasonic
Sensor. Remember what you learned from your previous activities and experiment
with different objects in front of the Ultrasonic Sensor to see if they are detectable.
You can also program the motors to stop when an object reaches a certain distance
from the Ultrasonic Sensor.
Try changing the distance units on the pulse Ultrasonic Sensor block from
centimeters to inches. Understanding how to use the Ultrasonic Sensor will give
your robot vision so that it can steer around objects and obstacles (Figure 44).
Figure 43
Figure 44
Further Investigate
In this sketch, the input of the Ultrasonic Sensor will turn different LEDs on or off.
If the variable in the if section of the loop block is true, then the blocks within the
do section of the loop block are run. In this instance, if there isn’t an object closer
than 10 cm to the Ultrasonic Sensor, the yellow LED on the PULSE controller will be
lit (Figure 43).
Tip: To solve this
extension activity, you
can find a sample sketch
in the appendix titled
GS_Activity_5_Extension_
Example.
Getting Started Activities 43