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.
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.
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.
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：
- Micro python Robot Course 1: Light up a LED
- Micro python Robot Course 2: LED light exchange lighting
- Micro python Robot Course 3.Breathing light
- Micro python Robot Course 4: Whistle
- Micro python Robot Course 5: Play《Little Star》
- Micro python Robot Course 6: Sound sensor
- Micro python Robot Course 7: Black line control light
- Micro python Robot Course 8: Measuring worker