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.

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).

ultrasound_mb2

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.

Advanced program

This program already works with variable speed. Based on the measured distance, it sets the speed of the Simple Car to the variable “speed”.

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