The ultrasonic sensor enables the robot to “see” objects by detecting them through ultrasonic feedback. In our experience, solid objects (walls, blocks, etc.) work best, soft or round objects do not return good readings.
The sensor measures the distance to an object and thus helps the robot act accordingly, for instance by avoiding obstacles or approaching them closely.
Attaching the Ultrasonic Sensor
Please follow pp. 42-47 in the EV 3 Manual (Building Instructions).
Programming the Ultrasonic Sensor
For this task, the robot approaches an object closely without touching it by using the ultrasonic sensor.
The following basic program is taken from screenshots of EV3 Programmer APP on a desktop computer (Please note: Certain programming blocks look slightly different in iOS versions of the app).
First, drag a <Move Tank Block> from the green tab on the lower menu. This block will make the robot drive close to the object (e.g., a wall).
Select <On>, which turns the driving motors on so that the robot approaches the object. Choose appropriate power between 0 and 100.
Next, drag a <Wait Block> from the orange tab menu.
Select <Ultrasonic Sensor>, <Compare>, and <Distance Centimeters>.
(Note: The ultrasonic sensor can also be programmed to detect inches).
Set the compare type to <Less Than>, and insert a suitable number of centimeters.
In the example below, the ultrasonic sensor detects an object that is less than 10 cm away. Once the robot falls below this distance, the next programming block will be run.
Finally, drag a second <Move Tank Block> from the green tab menu, and select <Off> which will turn the driving motors off.
Alternatively, you can also use a <Display Block> or a <Sound Block>.
© 2020 Dr. Krista Francis & Stefan Rothschuh