The Ultrasonic Sensor can measure the distance to an object in front of it. It does this by sending out sound waves and measuring how long it takes the sound to reflect back to the sensor. The sound frequency is too high for you to hear (“ultrasonic”).
You can measure the distance to an object in either inches or centimeters. You could use this to, for example, make your robot stop a certain distance from a wall.
You can also use the Ultrasonic Sensor to detect whether another ultrasonic sensor nearby is operating. For example, you could use this to detect the presence of another robot that is using an ultrasonic sensor nearby. In this “listen only” mode, the sensor listens for sound signals but does not send them.
Data | Type | Range | Notes |
---|---|---|---|
Distance in Centimeters | Numeric | 0 to 255 | Distance to object in centimeters. |
Distance in Inches | Numeric | 0 to 100 | Distance to object in inches. |
Ultrasound Detected | Logic | True/False | True if another ultrasonic sensor is detected. |
The Ultrasonic Sensor works best to detect objects with hard surfaces that reflect sound well. Soft objects, such as cloth, may absorb the sound waves and not be detected. Objects with rounded or angled surfaces are also harder to detect. |
The sensor cannot detect objects that are very close to the sensor (closer than about 3 cm or 1.5 inches). |
The sensor has a wide “field of view” and may detect a closer object off to the side instead of a farther object straight ahead. |
This program makes a robot gradually slow down and then stop about 10 cm away from anything it detects in front of it. The closer it gets to the object, the slower it will drive.
The program uses the Ultrasonic Sensor block in the Measure – Distance Centimeters mode to get a distance measurement and get the resulting number on a data wire. A Math block then subtracts 10 from the distance, and the result is wired to the Power input of a Move Steering block. Shorter distances result in lower power, and when the distance reaches 10 cm, the power will be zero, and the robot will stop. The process is repeated in a loop so that the motor power is adjusted continuously based on new distance measurements.
Block | Mode | Use |
---|---|---|
Wait | Ultrasonic Sensor – Compare – Distance | Wait for the distance to reach a certain value. |
Wait | Ultrasonic Sensor – Compare – Presence/Listen | Wait, in “listen only” mode, for an ultrasonic signal to be detected. |
Wait | Ultrasonic Sensor – Change – Distance | Wait for the distance to change by a certain amount. |
Loop | Ultrasonic Sensor – Distance | Repeat a sequence of blocks until the distance reaches a certain value. |
Loop | Ultrasonic Sensor – Presence/Listen | Repeat a sequence of blocks until an ultrasonic signal is detected, in “listen only” mode. |
Switch | Ultrasonic Sensor – Compare – Distance | Choose between two sequences of blocks based on the distance. |
Switch | Ultrasonic Sensor – Compare – Presence/Listen | Choose between two sequences of blocks based on whether an ultrasonic signal is detected in “listen only” mode. |
Ultrasonic Sensor | Measure – Distance | Measure the distance and get the result on a Numeric data wire. |
Ultrasonic Sensor | Measure – Presence | Listen for other ultrasonic signals in “listen only” mode, and get the result on a Logic data wire. |
Ultrasonic Sensor | Compare – Distance | Compare the distance to a threshold, and get the result on a Logic data wire. |
Ultrasonic Sensor | Compare – Presence/Listen | Listen for other ultrasonic signals in “listen only” mode, and get the result on a Logic data wire. |
Ultrasonic Sensor | Measure – Advanced | Similar to Measure – Distance, but with the option to make only a single sound ping. |
Data Logging | See Data Logging. |
Πηγή: https://ev3-help-online.api.education.lego.com/Education/en-us/page.html?Path=editor%2FUsingSensors_Ultrasonic.html