You are on page 1of 16

Home All Category Contact us Discount Join us

LoginRegister

English
Location: Home » Arduino Robot Car Kit » OSOYOO Robot Car Starter Kit Tutorial »
OSOYOO Robot Car Starter Kit Lesson 3: Obstacle Avoidance Robot Car

OSOYOO Robot Car Starter Kit Lesson 3:


Obstacle Avoidance Robot Car
Post Time: 2017-05-10 22:05:21 Category: OSOYOO Robot Car Starter Kit Tutorial

Authorized Online Retailers

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

 Objective
 Parts and Devices
 Hardware Installation
 Ultrasonic Sensor Position Alignment
 Software Installation:
 Testing
Objective

The installation of this lesson is based on Lesson 1 framework. If you haven’t finished the
assembly in Lesson 1, please review https://osoyoo.com/?p=4906 and complete the
installation.

In this lesson, we will add a servo motor, an ultrasonic module and a buzzer onto Lesson 1
framework. With these new devices, the car can “see” obstacle through ultrasonic sensor 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

Device Name picture qty Screw Number

M3 x 10 Screws and
Arduino UNO 1
nuts, washer

M3 x 30 Screws and
Motor with wires 4
nuts
M3 x 10 Screws and
OSOYOO MODEL X 1
nuts, washers
MOTOR driver module

Box for 18650 3.7V M3 x 10 Screws and


1
battery+ nuts

DC power connector 1

M3 x 10 Screws and
voltage meter 1
nuts, washers

M3 x 10 Screws and
SG90 Servo Motor 1
nuts, washers

M1.5 x 12 Screws
Ultrasonic module 1
and nuts

M3 x 10 Screws and
Buzzer Module 1
nuts, washers

Mount holder for Servo M2 x 10 Screws,


1
motor screws for sg90

Jumper wires(male-
some
female,female-female)

lower chassis 1 Copper pillar


upper chassis 1 Copper pillar

Hardware Installation

1) Regarding how to install chassis, arduino and motors, please refer to Lesson 1:

OSOYOO Robot Car Starter Kit Lesson 1: Install UNO R3 Board and Motors on Chassis

1) Connect the SG90 servo motor to the holder with screw M2 x 10

2) Connect the servo motor arm to brakect with 2 x screws which comes with the servo
motor, Connect the Ultrasonic Module to bracket with M1.5 x 12 screws and nuts
3)Fix the mount holder for servo motor on upper chassis with M3 x 10 Screws and nuts.

4) Put the arm with ultrasonic module on SG90 servo motor


5) Fix the Buzzer module with M3 X 10 screw and nut on upper chassis.

6)Wiring

Connect the buzzer module, ultrasonic module and servo motor as per below connection
diagram:

Uno R3 Board Buzzer Module


GND GND
3.3v VCC
I/O D13
Ultrasonic Module Uno R3 Board
GND GND
Echo D11
Tr1g D12
VCC 5V

Uno R3 Board
OSOYOO MODEL X Motor driver module
D2 IN1
D4 IN2
D5 ENA
D6 ENB
D7 IN3
D8 IN4
D9 S
SG90 Servo Motor OSOYOO MODEL X Motor driver module
Brown GND
Red 5v
Yellow S
Software Installation:

Prerequisite: If you have not installed Servo library , Download and install the  library from:
https://osoyoo.com/driver/Servo.zip

Step 1:Download Lesson One sample code fromhttps://osoyoo.com/driver/smartcar-


lesson3.zip  , unzip the download zip file smartcar-lesson3.zip, you will see a folder called
smartcar-lesson3 .

Step 2:  Connect Arduino UNO to PC with USB cable, Open Arduino IDE -> click file ->
click Open -> choose code “smartcar-lesson3.ino” in smartcar-lesson3 folder, load the code
into arduino.
Step 4:  Choose corresponding board/port for your project,upload the sketch to the board.
Ultrasonic sensor servo initial direction alignment

After turning on the battery, 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 battery 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, turn on battery again. After hearing the long beep, 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 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
https://osoyoo.com/2017/05/10/arduino_car_obstacle_avoidance/#7

Trouble Shooting

Is there an easy way to align my Ultrasonic sensor to make it facing front?


Step 1) Download https://osoyoo.com/driver/arduino_servo_car/servo.zip

Step 2) Unzip above file and run the servo.ino file in your car.
Your servo will move from left to right and finally stop to center position. If your ultrason
sensor is not facing to front direction. Please release your ultrasonic sensor from servo head,
re-position its direction to front , then fasten the sensor screw to fix its direction.
Step 3) After you have changed the sensor direction, please run smartcar-lesson3.ino sketch
again. Your car will begin to do obstacle avoidance driving.

DownLoad Url osoyoo.com

9 Comments

 raphaelnathan01 says:

December 20, 2019 at 10:47 am

Arduino:1.8.11 Hourly Build 2019/11/11 03:33 (Windows 10), ‫לוח‬:”Arduino Uno”

smartcar-lesson3:1:10: error: Servo.h: No such file or directory

compilation terminated.

exit status 1
Servo.h: No such file or directory

“Show verbose output during compilation”

Log in to Reply

o admin says:

July 23, 2020 at 2:59 am

Please Download and install the servo library from:


https://osoyoo.com/driver/Servo.zip

Log in to Reply

 raphaelnathan01 says:

December 20, 2019 at 10:49 am

Arduino:1.8.11 Hourly Build 2019/11/11 03:33 (Windows 10), ‫לוח‬:”Arduino Uno”


smartcar-lesson3:1:10: error: Servo.h: No such file or directory
compilation terminated.
exit status 1
Servo.h: No such file or directory
“Show verbose output during compilation”

Log in to Reply

o admin says:

December 20, 2019 at 10:27 pm

It seems that your Arduino IDE version does not support Servo library.
Normally Servo library should come with Arduino IDE.

I suggest you install the latest Windows Arduino IDE version and re-compile
the sketch again. Do not use Arduino IDE in linux. Linux Arduino IDE might
lack many libaries.

Log in to Reply

 raphaelnathan01 says:

December 22, 2019 at 6:51 am

Thanks a lot for your help everything works fine I’ll continue to the
next step

Log in to Reply

 yalostme747 says:

July 16, 2020 at 8:49 am

Wired it and uploaded the program, turned it on and it beeped. Then it proceeded to
shoot backwards.. how do I troubleshoot this?

Log in to Reply

o admin says:
July 16, 2020 at 9:38 am

does the robot rotate the two big eyes(ultrasonic sensor)?

Log in to Reply

 yalostme747 says:

July 23, 2020 at 12:31 am

It moves the eyes once off to the side.

Log in to Reply

 admin says:

July 23, 2020 at 3:05 am

In order to make sure beginning orientation of your ultrasonic


sensor(two BIG EYES) facing to front, the first two seconds
after you turning on the battery, the servo will rotate to
90degree position(stay there for 2 seconds). So if your
ultrasonic sensor is not facing the front at the beginning two
seconds, you need to turn off the battery. release your
ultrasonic sensor from servo and reposition it. Make it facing
front and fasten it.

If your ultrasonic sensor does not facing front at the beginning,


the car can not properly do obstacle avoidance.

Log in to Reply

Leave a Reply

You must be logged in to post a comment.

Privacy Policy © 2009-2017 Osoyoo.com

You might also like