Robot Kit for Micro:bit Tutorial 6.2 Distance control light
1.Preparation
1-1.The position of the Ultrasonic module on the robot car
1-2.Learn about the principle of Ultrasonic module
Programming method:
Mode 1 online programming: First, we need to connect the micro:bit to the computer by USB cable. The computer will pop up a USB flash drive and click on the URL in the USB flash drive: http://microbit.org/ to enter the programming interface. Add the Yahboom package: https://github.com/lzty634158/Tiny-bit to program.
Mode 2 offline programming: We need to open the offline programming software. After the installation is complete, enter the programming interface, click【New Project】, add Yahboom package: https://github.com/lzty634158/Tiny-bit, you can program.
In the picture shown below, the ultrasonic module with red wire frame.
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
2.Learning goal
2-1. Learn how to use ultrasonic return distance graphically program building blocks
2-2.In this lesson, we will learn how to change the brightness of the RGB searchlight according to the distance
3.Search for block
The following is the location of the building blocks required for this programming.
4.Combine block
The summary program is shown below:
5.Experimental phenomena
After program is downloaded,We can see that the brightness of the RGB searching lights be changed when the distance of the object directly in front of the Tiny-bit be changed. The farther away the distance, the smaller the brightness. When the distance is greater than 20cm, the RGB searching lights will go out.

The code of the experiment: 2.Distance control light.rar
Playing with Tiny bit Microbit Robot Tutorial:
- Robot Kit for Micro:bit Tutorial 6.1 Measuring worker
- Robot Kit for Micro:bit Tutorial 6.2 Distance control light
- Robot Kit for Micro:bit Tutorial: 6.3 Ultrasonic obstacle avoidance
- Robot Kit for Micro:bit Tutorial 6.4 Magic hand
- Robot Kit for Micro:bit Tutorial: 6.5 Radar detector
- Robot Kit for Micro:bit Tutorial 6.6 Playing black paino
- Robot Kit for Micro:bit Tutorial: 6.7 Tracking
- Robot Kit for Micro:bit Tutorial: 6.8 Voice control light
- Robot Kit for Micro:bit Tutorial 6.9 Coward
- Robot Kit for Micro:bit Tutorial: 6.10 Musical rhythm
- Robot Kit for Micro:bit Tutorial: 6.11 Listener
- Robot Kit for Micro:bit 6.12 Wobble when touch
- Robot Kit for Micro:bit Tutorial: 6.13 Spinning top
- Robot Kit for Micro:bit Tutorial: 6.14 Frog beating
- Robot Kit for Micro:bit Tutorial: 6.15 Adventure car