US-016 wiring
MB1
The ultrasonic sensor is powered from the expansion board via pins 3V3 a GNDNext, you need to connect the output from the ultrasonic sensor, i.e. pin Oct to the micro:bit analog input pin. In this case we chose the pin P2.
MB2
MB3
Connection (TRIG and ECHO)
The ultrasonic sensor is powered from the expansion board via pins 3V3 a GND. Next, you need to connect the pin for the transmitter (Trig) and the receiver (Echo). In the following programs, we use the pins P14 – Echo a P15 – Trig.
MB1
MB2
MB3
Programmes
The programs again differ according to the type of ultrasonic sensor. They are further divided according to the expansion board used. The MB1 board is equipped with a built-in LED strip, which is great for indicating the distance that the sensor measures.
However, in principle, the programs are the same, they only differ in the use of the Neopixel library for the LED strip.
Sensor US-016
Expansion board MB1
Basic program
This program uses the LED strip that our MB1 expansion board has. If you use this program on another board, it will work too, but it will unnecessarily send signals to the empty pin P16. Therefore, we recommend uploading the code below.
First, we initialize the LED strip using the Neopixel library. The built-in strip has 8 LEDs and is connected to pin P16 (that's why this pin is not brought out on the MB1 board).
The distance is then read in the loop. If the distance is less than the limit we have chosen, 10 cm, the tank stops. We set the color of the LED strip to red. If this condition is false, the tank starts moving at the selected speed and we set the LED strip to green. Finally, we light up the strip.
Advanced program
Expansion board MB2 and MB3
Basic program
Advanced program
This program already works with variable speed. Based on the measured distance, it sets the speed of the tank to the variable “speed”. By changing the value of the constant DIST_MIN or DIST_MAX You can adjust the range of measured distances.
Common sensors (TRIG and ECHO)
Expansion board MB1
Basic program
This program uses the LED strip that our MB1 expansion board has. If you use this program on another board, it will work too, but it will unnecessarily send signals to the empty pin P16. Therefore, we recommend uploading the code below.
First, we initialize the LED strip using the Neopixel library. The built-in strip has 8 LEDs and is connected to pin P16 (that's why this pin is not brought out on the MB1 board).
The distance is then read in the loop. If the distance is less than the limit we have chosen, 10 cm, the tank stops. We set the color of the LED strip to red. If this condition is false, the tank starts moving at the selected speed and we set the LED strip to green. Finally, we light up the strip.
Advanced program
Expansion board MB2 and MB3
If you have a tank with an MB2 or MB3 expansion board, the previous programs will work exactly the same. The difference is that it will send a signal to the empty pin P16, which is connected to the LED strip on the MB1 board. The following codes are therefore exactly the same, the only difference is that they do not contain the control of the LED strip using the Neopixel library.
Basic program
Same function as the program for the MB1 board, only without LED.
Advanced program
Same function as the program for the MB1 board, only without LED.



