Simple Car – Ultrasound

Expand your Simple Car with the Ultrasound module! Connect it to your existing building kit and learn how to use the ultrasonic sensor to detect obstacles and program the vehicle to automatically avoid them - a great addition for developing logical thinking, algorithmization, and programming in practice.

Description

Ultrasound is an expansion module for Simple Car that enables obstacle detection using an ultrasonic sensor. Thanks to this sensor, the vehicle can recognize objects in its vicinity and react to them - for example, stop or change direction, without the need for manual steering. Simply connect the module to the vehicle's base and in a moment it is ready for smart obstacle avoidance.

Ultrasound expands the possibilities for both educational and fun projects – from autonomous driving simulations to exploring unknown spaces. It is ideal for both complete beginners who want to learn the basics of sensor technology and more advanced users who want to create more complex algorithms and behaviors.

US-016 wiring

The ultrasonic sensor is powered from the expansion board using pins 3V3 and GND . Next, you need to connect the output from the ultrasonic sensor, i.e. pin Out , to the analog input pin of the micro:bit. In this case, we chose pin P2.

MB2

MB3

ultrasound2_mb3

Connection (TRIG and ECHO)

The ultrasonic sensor is powered from the expansion board using pins 3V3 and GND . It is also necessary to connect a pin for the transmitter (Trig) and receiver (Echo). In the following programs, we use pins P14 – Echo and P15 – Trig.

MB2

ultrasound_mb2

MB3

ultrasound_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

Basic program

The program in the loop measures the distance of the object from the ultrasonic sensor. If this distance is greater than 10 cm, the tank moves forward. Otherwise, it stops.

Advanced program

This program already works with variable speed. Based on the measured distance, it sets the tank speed 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)

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.

Tasks

Task 1: Obedient vehicle

Make your Simple Car a playful creature. Reverse the stop-and-go logic so that if it detects an obstacle in front of it, it will go straight after it. You can control the vehicle with a hand movement, for example - when you move it closer, it will go after it, and when you move it further away, it will stop.

Task 2: Safe vehicle

Create a program that allows the vehicle to avoid obstacles. When it detects an obstacle in front of it, it stops, turns to the side, and continues driving. Set the turn to be long enough for the vehicle to actually avoid the obstacle.

Task 3: Robotic vacuum cleaner

Simulate the behavior of a robotic vacuum cleaner. The vehicle moves forward, and when it encounters an obstacle, it stops, reverses, and turns a random angle to continue in a different direction. Use the "random number" block from the Math library to generate a random direction.

Task 4: Patrolling

Plan a route that the vehicle will automatically follow until it encounters an obstacle. Then react – for example, turn around and continue in a different direction. This simulates a simple patrol vehicle that finds its way on its own.

Gallery