Ultrasonic Sensor

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

Please find a printable version of this page HERE.

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 LEGO Mindstorms Education EV3Classroom™ on a desktop computer.


First, drag a <Move> Block from the pink Movement menu. This block will make the robot drive towards the object (e.g., a wall).

To set the speed, choose appropriate power between 0 and 100.


Next, drag a <Wait> Block from the blue Sensor menu.

Select the block with the Ultrasonic Sensor (note the icon).

Select the correct port. Check where you plugged the sensor into the base: The ports are labelled 1-4.

Set the distance:

In the example, once the Ultrasonic Sensor detects an object that is less than 10 cm away, the next block will be run.

The Ultrasonic Sensor can also be programmed to detect inches.


Finally, drag a second <Move> Block from the pink tab menu to stop the forward motion.

Please find a printable version of this page HERE.

© 2022 Dr. Krista Francis & Stefan Rothschuh