Academic Journal of Science and Technology ISSN: 2771-3032 | Vol. 10, No. 1, 2024 146 An Infrared Obstacle Avoidance Car Based on STM32 Qiuli Wang, Jiying Chen, Zimo He, Feiyang Han, Jiayi Liu School of Southwest Petroleum University, Chengdu 610500, China Abstract: With the rapid development and wide application of artificial intelligence technology, the function of intelligent obstacle avoidance vehicle is becoming increasingly prominent. This article presents a design and realization method of infrared obstacle avoidance intelligent car based on STM32 MCU. The design is driven by two DC motors as main power sources. The motor drive circuit adopts L298N driver chip to control the DC motor to achieve the purpose of controlling the trolley. The infrared obstacle-avoidance sensor is used to judge obstacles and road conditions, and the distance between the car and obstacles is monitored in real time. The error caused by external physical condition can be eliminated by the calibration and optimization of the infrared obstacle avoidance module and the program of the single-chip microcomputer, so as to achieve the goal of accurate location of obstacles. Keywords: STM32 MCU; infrared sensor; obstacle avoidance. 1. Introduction In the environment of the rapid development of computer and internet of things technology, the research on automation technology is also continuously deepening. Intelligent trolleys are gradually emerging, which not only become the key equipment in the fields of automated logistics and transportation, machinery production, but also can be widely used in manufacturing, military, mining and other fields. Under this background, this paper designs an intelligent infrared obstacle avoidance car, which is based on infrared reflection ranging algorithm to avoid obstacles. After debugging, the obstacle avoidance trolley can realize the function of obstacle avoidance under various road conditions. 2. The Overall Design The intelligent obstacle avoidance trolley system based on STM32 is composed of STM32 single chip microcomputer (STM32F103RCT6), infrared obstacle avoidance module, DC motor module, motor drive module and power module. A block diagram of the system is shown in Fig. 1. Figure 1. System design block diagram 3. Working Principle Infrared sensors are installed on the left and right sides of the front of the obstacle avoidance car body to detect obstacles in front of it, which is used to determine whether it is necessary to turn and prevent the car from hitting obstacles. The single chip microcomputer receives and processes the input information, and outputs the result to the motor drive module to control the operation of the DC motor. And by receiving the signal generated by the single chip computer to drive the motor operation, so as to control the direction and speed of the car. The transmitter tube emits infrared light with a wavelength of 940 nm. When an obstacle (reflective surface) is detected in front, the infrared light is reflected back and received by the receiving tube. After processing by the comparison circuit, the output signal is sent to the MCU. The single-chip microcomputer controls the direction and speed of motor rotation to avoid obstacles. The system adopts 12 V power supply to provide a large current for the motor drive module to ensure the normal operation of the DC motor. 4. Hardware Design 4.1. Main control circuit STM32F103RCT6 is a 32-bit microcontroller based on ARM Cortex-M3 kernel, which has rich peripherals and high performance processing capability. Cooperate with the programming software Keil uVision5 to control the power supply burning module, power supply module, infrared receiver module, motor drive module and other related modules. 4.2. Motor drive module The L298N motor driver module is a double H-bridge motor driver. The working principle is to control the rotation direction and speed of the motor by controlling the voltage on the H-bridge output port. When the voltage on the output port is high, a switching tube of the H-bridge directs the current to a port of the motor. When the current on the output port is low, another switching tube of the H-bridge will direct the current to the other port of the motor. The rotation direction of the 147 motor is controlled by alternating high and low voltage output. In order to control the motor rotation speed, the motor drive module uses PWM (pulse width modulation) technology. The speed of the motor is controlled by changing the voltage time on the output port. The longer the time on the output port, the faster the motor speed. The shorter the voltage time on the output port, the slower the motor speed will be. The circuit schematic diagram is shown in Fig. 2. Figure 2. Schematic diagram of L298N circuit 4.3. Infrared obstacle avoidance module This design uses infrared obstacle avoidance module for obstacle avoidance, which has a pair of infrared transmitting and receiving tubes. LM393 chip is used inside the module, and the internal circuit diagram is shown in Fig. 3. Figure 3. Schematic diagram of infrared obstacle avoidance circuit The working principle is that the transmitter tube emits infrared light signal with wavelength of 940 nm, and when encountering obstacles, it will reflect back and receive it through the receiving tube. After processing by the comparator circuit, the green indicator light is on, and the signal output interface will output a low level digital signal. If you want to change the detection distance of the infrared obstacle avoidance module, it can be adjusted through the potentiometer knob, and the effective detection distance range is 2 ~ 30cm. When the emitted infrared is not reflected back or is reflected back but the intensity is not large enough, the infrared receiving tube is always in the off state, the signal output interface is a high level of digital signal, and the green indicator is extinguished. The sensor module has strong adaptability to environmental light, can be adjusted by potentiometer, easy assembly, easy to use, etc. It can be widely used in many occasions such as robot obstacle avoidance, obstacle avoidance car, assembly line counting and black and white line tracking. The working principle block diagram is shown in Fig. 4. Figure 4. Working principle of infrared sensor 5. Software The system software is programmed in C language and compiled with Keil μVision5. First of all, each module is initialized and the data stored before is cleared. Then the sensor sends the obtained information to the pin of the single chip microcomputer. After judging and processing, the single chip microcomputer realizes the autonomous control of the car. In this design, the obstacle avoidance program is the basis of line avoidance and inclined plane obstacle avoidance. The obstacle distance set in this design is 15 cm, that is, when the distance between the object in front and the car measured by the ultrasonic sensor is no more than 15 cm, it will be considered that there is an obstacle in front, and the corresponding obstacle avoidance operation will be carried out. The flow of obstacle avoidance program is shown in Fig. 5. Figure 5. Flowchart of obstacle avoidance program 6. Debug Results First, the site is cleared to ensure that there is enough space for the car to drive, and then to ensure that there are no obstacles to test the forward or backward function of the car. After the car moves forward and backward without mistakes or problems. Randomly place obstacles. When the obstacle avoidance car encounters an obstacle, when the distance from the obstacle is greater than 15cm, the motor will be driven to control the wheel moving at a constant speed. If the obstacle is found to be less than 10cm in the left front, the infrared sensor in the left front will transmit the signal to the microcontroller, and after processing, the microcontroller will 148 control the car to step back and turn to the right to avoid the obstacle. If the obstacle is found in the right front less than 10cm, the infrared sensor in the right front will send the signal to the single chip microcomputer, and after processing, the single chip microcomputer will control the car to retreat and turn left to avoid the obstacle. If the obstacle is found in the front less than 10cm, the two infrared sensors will send the signal to the single chip microcomputer, and after processing, the single chip microcomputer will control the car to retreat to the appropriate distance. Signals from infrared sensors determine the direction of the turn to avoid obstacles. The real picture is shown in Fig. 6. Figure 6. Physical picture 7. Summary The obstacle avoidance system designed in this paper based on STM32 intelligent car uses the Internet of Things technology to integrate high-performance, low-power STM32 chip with a variety of sensors through software programming to detect road information in real time, so that the car can complete simple obstacle avoidance. At the same time, the whole car adopts screws to fix each module on the car body, which is simple in structure, easy to install, easy to operate, and has strong practical significance. Through the design of this topic, the related knowledge of microcontroller and sensor has a more comprehensive and deeper understanding, but also master the principle of DC drive circuit and PWM speed regulation circuit. References [1] WANG Yanwen, WANG Ershen, ZHAO Zhijie, et al. Design of Multi-function Measurement System Based on Intelligent Car [J]. And electronics, 2019 (1) : 184-188. [2] Lu Wei. The design and implementation of intelligent vehicle obstacle avoidance system [D]. Nanchang: nanchang university, 2012. [3] li lei, Cao Shenghui. The realization of the intelligent car obstacle avoidance technology [J]. Journal of micromotor, 2011, 44 (6) : 109-111. [4] xue-hong lu, shao runner-up. Design and Function Realization of autonomous Tracking Obstacle Avoidance System Based on STM32 Intelligent Car [J]. World Nonferrous Metals, 2019, 36 (22) : 165-168.