5% OFF Over $19, Code: Elephant5; 10% OFF Over $59, Code: Elephant10

STM32 Visual Tracking Car Tutorial 3.7 Ultrasonic obstacle avoidance

Posted by Fiona Su on

1) Preparation


1-1  STM32 expansion board


1-2 STM32 smart car



1-3  Ultrasonic module


2) Purpose of Experimental

After the car is powered on, press the start button next to the PS2 logo on the expansion board. When the current side has obstacles, the car turns to 90 degrees.

3) Principle of experimental

The ultrasonic module is a sensor that uses ultrasonic characteristics to detect the distance. It has two ultrasonic probes for transmitting and receiving ultrasonic waves. The range of measurement is 3-450 cm.


3-1 Ultrasonic emission and reception schematic

(1) You need to input a high level signal of at least 10us to the Trig pin to trigger the ranging function of the ultrasonic module.                     

image.png3-2  Ultrasonic module sends trigger signal

(2) After the ranging function is triggered, the module will automatically send out 8 ultrasonic pulses with 40 kHz and automatically detect whether there is a signal return. This step is done internally by the module.



(3) When the module detects an echo signal, the ECHO pin will output a high level. The high level duration is the time from when the ultrasonic wave is sent to when it returns. You can calculate the distance by using the time function to calculate the high level duration. Formula: Distance = High level duration * Speed of sound(340M/S)/2.

4) Experimental Steps

4-1 About the schematic


4-1 STM32 main control board circuit diagram


4-2 Ultrasonic module interface

4-2  According to the circuit schematic:

Trig(Ultrasonic module)------PA4

Echo(Ultrasonic module)------PA5

4-3  About the code

Please see the folder named Ultrasonic obstacle avoidance in the code folder.

The code of the experiment:  7.Ultrasonic_obstacle_avoidance.rar

STM32 Visual Tracking Car Tutorial Overview

2.Development environment

3.Experimental tutorial

4. About battery

5. About installation


Buy the STM32 Visual tracking robot car



Leave a comment

Please note, comments must be approved before they are published