Our Goal

Requiered Materials


What is ultrasonic

ultrasonic is a sound wave with a frequency higher than 20,000 Hz. It has good directionality, strong penetrating ability, easy to obtain concentrated sound energy, and has a long distance in water. It can be used for distance measurement, speed measurement, cleaning, welding, crushing, Sterilization, etc.

Principle of ultrasonic ranging

The ultrasonic transmitter emits ultrasonic waves in a certain direction, and starts timing at the same time as the transmission time. The ultrasonic waves propagate in the air, and immediately return to the obstacle when the obstacle is encountered on the way, and the ultrasonic receiver stops timing immediately on receiving the reflected wave. Calculate the distance according to the time when the receiver receives the ultrasonic wave, similar to the radar ranging.

Ultrasonic modules

Hardware connect

As below picture, connect the ultrasonic module to robit board with 3 pin wire.




Step 1

Note:If you get a warning telling you some packages will be removed because of incompatibility issues, either follow the prompts or create a new project in the Project file menu.

Step 2

Snap the foreverblock from the Basic, then snap show number under it.

Snap the Ulirasonic distance from the Sonarbit, then choose cm & P1. This is a return data cm for connecting ultrasonic module to the P1.


Program link:https://makecode.microbit.org/_DdTdurbyrVvH

If you don’t want to type these code by yourself, you can directly download the whole program from the link below:

Note: The largesr ranging distance of the ultrasonic module is almost 400cm.


The ultrasonic module will get feedbacks about distance in time and show the result on the 5X5 screen if the micro:bit.


In what conditions that the distance is 0 ?


More Information