In this mode, the car will move forward. If it detects an object in front of it, the car will stop, turn left and begin to move forward again until it detects another object.
Install additional module
This program requires an addition module to be added to your Arduino IDE.
Please download the AFMotor.zip module and add it to your Arduino IDE
To Add the AFMotor to your Arduino IDE: Select Sketch -> Include Library -> Add ZIP Library, then select the downloaded file,
When the transmitting pin of the ultrasonic module detects an obstacle in front, the reflected pin will receive the signal and transmit it to the MCU through IO pin. After the SIGNAL is received, the MCU will drive the L298N module to realize the corresponding action of the motor. For example, if an obstacle is detected in the front range less than 30cm and larger than 10cm, the MCU will control the car to retreat successively and then turn left; while in the front range less than 10cm, the car will stop, while in the front range greater than 30cm, the car will move forward without any obstacle detected.