I. Objective
II. Parts and Devices
III. Hardware Installation
IV. Software Installation
V. Functional Testing and Verification
VI. Troubleshooting


In this lesson, we will do an obstacle avoidance auto-driving project. We use an ultrasonic module to “see” obstacle, and the car will turn around from the obstacle automatically.

You must complete lesson 1 before you continue on with this lesson.


OSOYOO ESPro Robot car chassis x1
OSOYOO Wheels x2
OSOYOO DC motors x2
OSOYOO ESPro motor driver board x1
OSOYOO Voltage meter x1
OSOYOO MG90 servo motor x 1
OSOYOO Mount holder x1
OSOYOO Ultrasonic module x1
OSOYOO Battery box x1
OSOYOO 3pin female to female jumper wire x1
OSOYOO 4pin female to female jumper wire x1
18650 Batteries (3.7 V) x2
Battery charger x1


Step (1) Install Ultrasonic Module to mount holder with 4pcs M1.4*8 screw and M1.4 nuts.

Step (2)Install mount holder for Ultrasonic Module on servo motor with M2*4 Self Tapping screw.

Step (3) Before connecting wires, Please keep all lesson 1 connections same as it is.
Connect SG90 servo motor and Ultrasonic Module to OSOYOO ESPro motor driver board using 4pin female to female jumper cable as follows.


Open-source Arduino
Software(IDE)
Download Arduino IDE here:
https://www.arduino.cc/en/Main/Software?setlang=en
7 zip is a free zip
utility that un-zips zip files
Download 7zip here for free
https://www.7-zip.org/

Step 1: Install latest Arduino IDE (If you have Arduino IDE version after 1.1.16, please skip this step). Download Arduino IDE from https://www.arduino.cc/en/Main/Software?setlang=en , then install the software.

Step 2:

Download https://osoyoo.com/driver/espro-2wd-car/espro-lesson2-tracking-line.zip, unzip the download zip file espro-lesson1-basic.zip, you will see a folder called espro-lesson2-tracking-line.zip.

Step 3:  Download Library Code:  https://osoyoo.com/driver/ESP32Servo.zip , and upload to Arduino IDE.

Open Arduino IDE ->Sketch-> Incilude Library ->Add .zip Library, Add ESP32Servo.zip file to Arduino IDE

Step 4:Connect ESPro motor driver board to PC with cable, Open Arduino IDE -> click file -> click Open -> choose code “espro-lesson2-tracking-line.ino” in lesson1 folder,Then in Tool->Board, select esp32 ->ESP32 Dev Module,
Last select correct port which matches ESP32 board,upload the sketch to the board.




Ultrasonic sensor servo initial direction alignment
After turning on the battery, the servo will make some movement and finally stops at front direction for 3 seconds.

If the ultrasonic sensor does not face the front during this first 3 seconds, you should turn off battery immediately and remove the sensor from the servo, reinstall it and make it facing straight forward direction as following picture. Otherwise, the obstacle avoidance program will not work properly.

After adjusting sensor direction, turn on battery again, the sensor should face front same as following picture. If its direction is not straight forward, turn off battery and do direction alignment again.

Final Testing :

After turning on the battery switch on the battery box, if the ultrasonic module turn to front view position, that means you don’t need to adjust sensor position anymore. Just wait 3 seconds. If no obstacle is detected, the car will go forward. If any obstacles are detected, the car will stop, the ultrasonic module will turn from right to left to detect surrounding obstacles. The robot car will decide to make left turn, right turn or backward according to obstacle sensor data and our obstacle avoidance algorithm.

Sometimes your car might have collision and make your Ultrasonic sensor position change, you must remember to do sensor direction alignment again as per link Ultrasonic sensor servo initial direction alignment.