Authorized Online Retailers

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


The installation of this lesson is based on Lesson 1 framework. If you haven’t finished the assembly in Lesson 1, please review 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
Screw Number
OSOYOO Basic Board for Arduino
M3 x 10 Screws and nuts, washer
Motor with wires
M3 x 30 Screws and nuts
OSOYOO MODEL X MOTOR driver module
M3 x 10 Screws and nuts, washers
Box for 18650 3.7V battery+
M3 x 10 Screws and nuts
DC power connector
voltage meter
M3 x 10 Screws and nuts, washers
SG90 Servo Motor
M3 x 10 Screws and nuts, washers
Ultrasonic module
1 M1.5 x 12 Screws and nuts
Buzzer Module
M3 x 10 Screws and nuts, washers
Mount holder for Servo motor
M2 x 10 Screws, screws for sg90
Jumper wires(male-female,female-female)
lower chassis
Copper pillar
upper chassis
Copper pillar

Hardware Installation

1) Regarding how to install chassis, Basic board 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.


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

Uno R3 Board Buzzer Module
3.3v VCC
I/O D13

Ultrasonic Module Uno R3 Board
Echo D11
Tr1g D12

Uno R3 Board OSOYOO MODEL X Motor driver module
D2 IN1
D4 IN2
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:

Step 1:Download Lesson One sample code from  , unzip the download zip file, you will see a folder called smartcar-lesson3 .

Step 2:  Connect Basic board 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 Basic board.

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

Trouble Shooting

Is there an easy way to align my Ultrasonic sensor to make it facing front?
Step 1) Download

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.