Welcome to MSPM0 Smart Robot Car repository
4.Ultrasonic avoid
Ultrasonic avoid
Ultrasonic avoid1. Software-Hardware2. Brief Principle2.1 Hardware Schematic Diagram2.2 Physical Connection Diagram2.3 Control Principle3. Main Functions4. Experimental Phenomenon
This tutorial is a comprehensive experiment combining multiple peripherals. You can understand individual peripherals before conducting this experiment.
1. Software-Hardware
KEIL5
MSPM0G3507 Robot Development Board
Ultrasonic module, TT encoded motor*2: external
Type-C data cable or DAP-Link
For program download or simulation to the development board
2. Brief Principle
2.1 Hardware Schematic Diagram

.png)
2.2 Physical Connection Diagram
- Wiring
.png)
Ultrasonic Module:
Note: When using servo PTZ, you need to add jumper cap to connect 5v and choose, see white line.
2.3 Control Principle
Obtain the distance of objects in front through the ultrasonic module, and control the car to move forward, backward, turn left, and stop based on the distance.
The ultrasonic module can obtain the distance of obstacles in front. We use this distance to determine the obstacle position relative to the car: If the obstacle is within the set distance range of the car, we call the car's stop, reverse, and turn left functions in the corresponding judgment function; If the obstacle is not within the set distance range of the car, we control the car to move forward.
- Program Flowchart

| Module | Function |
|---|---|
| Ultrasonic Module | External information collection: obtain obstacle distance |
| Motor | Motion control |
3. Main Functions
This tutorial does not use PID control for car movement
xxxxxxxxxxFunctions introduced before will not be explained again!
Function: get_distance
| Function Prototype | void get_distance(uint16_t distance) |
|---|---|
| Function Description | Ultrasonic obstacle avoidance program |
| Input Parameters | distance: maximum distance for ultrasonic steering |
| Return Value | None |
4. Experimental Phenomenon
After successfully downloading the program, press the RESET button on the development board and observe the car's effect!
xxxxxxxxxxFor program download, refer to [3. Development Environment Setup and Usage: 3.Uniflash Programming]
Phenomenon:
With obstacle: The car first stops, then judges the distance, and turns left based on the distance
Without obstacle: The car moves forward
For specific judgment, refer to the flowchart or code.