Connection
The connection of the ultrasound to the MB2 board can be found in the diagram. The ultrasonic sensor uses power from the board, namely from the 3V3 and GND pins. It is also necessary to connect the pin for the transmitter (Trig) and the receiver (Echo).
Program
Programming Simple Car – Ultrasound is divided into two parts: basic program a advanced detection obstacles using an ultrasonic sensor. First, you set the correct version of the expansion board using the block Init tank version and you will use a simple program that stops the vehicle when it detects an obstacle. In the advanced version, you can then create more complex behaviors – such as avoiding obstacles, following a hand, or randomly choosing a direction when an object is detected – to give the vehicle its own “decision-making”.
Basic program
The distance is read in the loop. If the distance is less than the limit we have chosen of 10 cm, the tank stops.



