Authorized Online Retailers:

Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES Buy from JP

Objective

In this lesson, you must complete lesson 4 before you continue on with this lesson. we use the ultrasonic module to “see” obstacle and measure the distance. If the distance is less than predefined threshold value, the buzzer will beep and the car will turn around from the obstacle automatically.

Parts and Devices

Hardware Installation

Install the smart car basic frame work as per Lesson 4 .If you have already completed installation in Lesson 4,  just keep it as is.


Software Installation:

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 sample code from Lesson 5 simple code , unzip the download zip file lesson5.zip, you will see a folder called lesson5.

Step 3: Connect Arduino UNO to PC with USB cable, Open Arduino IDE -> click file -> click Open -> choose code “lesson5.ino” in lesson5 folder, load the code into arduino.

Step 4: Choose corresponding board/port for your project,upload the sketch to the board.

Step 5:Ultrasonic sensor servo initial direction alignment

After power on the car, you will hear a long beep sound, then the servo will make some movement and finally stops at a direction for 5 seconds.

During this first 5 seconds, you must make sure the Ultrasonic sensor(two eyes) is facing straight forward.

If it is not straight forward, you should turn off the car immediately and remove the sensor from 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, power on the car again. After hearing the long beep, the sensor should face front same as following picture. If its direction is not straight forward, turn off the car and do direction alignment again.

Final Testing :

Power on the car, if the ultrasonic module turn to front view position, that means you no need adjust sensor position anymore. Just wait 5 seconds. If no obstacle is detected, the car will go forward. If any obstacles is detected, the car will stop, the ultrasonic module will turn from right to left to detect surrounding obstacle. 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