Spring Sale: 5% OFF Over $89, Code: Elephant5; 10% OFF Over $149, Code:Elephant10

Micro python Robot Course 8: Measuring worker

Posted by SuFiona on

Learning goal

This lesson learns how to use the Ultrasonic sensor on the Tiny-bit microbit robot.


1.The position of the Ultrasonic module in the robot, as shown below.


2.Ultrasonic ranging principle:

The ultrasonic wave has two ultrasonic probes, which are used for transmitting and receiving ultrasonic waves, respectively, and the measurement range is about 3-450 cm. First, input a 15us high level signal to the SCL (TRIG) pin to start the ranging function of module.

After the ranging function is started, the module will automatically send out 8 40 kHz ultrasonic pulses and automatically detect whether there is a signal return. This step is automatically done internally by the module. When the echo signal is detected, the echo terminal SDA (ECHO) pin will output a high level.

The high level duration is the time from the transmission to the return of the ultrasonic wave. We can calculate the current distance by the high level duration.

Formula: Distance = High Time * Sound Speed (340M/S)/2.

From the hardware interface manual, we can know that the tracking sensor is directly driven by the micro:bit P15,P16 pin.

image.png Code


 Programming and downloading

1.You should open the Mu software, and enter the code in the edit window, , as shown in Figure 8-1.

Note! All English and symbols should be entered in English, and the last line must be a space.

image.png Figure 8-1

2.As shown in Figure 8-2, you need to click the Check button to check if our code has an error. If a line appears with a cursor or an underscore, the program indicating this line is wrong.

image.png Figure 8-2

3.You need to connect the micro data cable to micro:bit and the computer, then click the Flash button to download the program to micro:bit as shown in Figure 8-3.

image.png Figure 8-3

4. After downloading the program, we will see that the distance will be dispaly on the micro:bit dox matrix.

The code of the experiment:  8.Measuring worker.zip

Micro python Robot Course:


Leave a comment

Please note, comments must be approved before they are published