Welcome to Building:bit Superkit repository
2.1 Hand-held range finder
Hand-held range finder
Hand-held range finder1. Learning objectives2. Building blocks3. Sensor wiring4. Code analysis5. Write and download the program6. Experimental phenomenon
1. Learning objectives
In this course, we mainly learn how to implement handheld rangefinder of ultrasonic module through python programming.
2. Building blocks
For the steps of building blocks, please refer to the installation drawings of [Assembly Course]--[ultrasonic handheld rangefinder] or the building block installation album in the materials.
3. Sensor wiring
Ultrasonic is connected to the P1P2 interface.

4. Code analysis
For the program of this course, please refer to the Hand-held-range-finder.py file.
from microbit import *import WOM_Sensor_KitFirst, import the libraries needed for this lesson from microbit: WOM_Sensor_Kit library for sensors;
xxxxxxxxxxwhile True:display.scroll(WOM_Sensor_Kit.WOM_ultrasonic(pin2, pin1))sleep(100)display.scroll('CM')In the infinite loop, microbit reads the data and unit of the ultrasonic sensor and displays it on the dot matrix.
5. Write and download the program
- Open the Mu software and enter the code in the editing window. Note! All English and symbols should be entered in English mode, use the Tab key for indentation, and the last line ends with a blank program.
- Click the thumb 'Check' button to check if there are any errors in our code. If a cursor or underline appears in a line, it means a syntax error. Please check and modify it. If there is no error, the lower left corner will prompt that there is no problem with the detection.

- Click the ‘REPL’ button to check whether the Superbit library has been downloaded. If not, please refer to [Preparation before class] --> [2.4 Python Programming Guide].

- After the program is written, connect the computer and the microbit mainboard with a microUSB data cable, and click the ‘Flash’ button to download the program to the micro:bit mainboard. (You need to click the ‘REPL’ button again to turn off the import library file function before you can download the program normally).

- If the download fails, please confirm whether the microbit is properly connected to the computer via the microUSB data cable and the Superbit Python library has been imported.
6. Experimental phenomenon
After the program runs successfully, the microbit dot matrix displays the distance and unit measured by ultrasound.