Note: ALL OSOYOO Products for Arduino are Third Party Board which is fully compatible with Arduino

Authorized Online Retailers

Where to buy the set with 18650 batteriese and USB charger

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

Buy the V2.1 Robot car without Battery and charger:

Buy from OSOYOO 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, 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.

You must complete lesson 1 (assembling the car) before you continue on with this lesson.

Parts and Devices

No. Picture Device Qty. Accessories Link
1 Ultrosonic Sensor 1 M1.4*8 Screw x 4
M1.4 Nut x 4
Click here to buy
2 Servo Motor 1 M2.2*8 Self Tapping Screw x 2
M2*4 Self Tapping Screw x 1
Click here to buy
3 Mount Holder for Ultrasonic Sensor 1 M1.4*8 Screw x 4
M1.4 Nut x 4
M2*4 Self Tapping Screw x 1
Click here to buy
4 Buzzer Sensor Module 1 M3 Plastic Screw x 1
M3 Plastic Nut x 1
M3 Plastic Pillar x 1
Click here to buy
5 20Pin jumper wire Male to female 20cm some Click here to buy
6 Philips screwdriver 1 Click here to buy
7 Hex Screwdriver 1 Click here to buy
8 M2*4 self tapping screw 1
9 M2.2*8 self tapping screw 2
10 M1.4*8 screw and nut 4
11 M3 plastic screw 1
12 M3 plastic pillar 1
13 M3 plastic nut 1

Hardware Installation

Step 1: Install the smart car basic frame work as per Smart Car Lesson 1 .If you have already completed installation in Lesson 1 , Everything keep it as is except move ENA from D9 to D3(we need D9 for Servo control). If you have installed Lesson 2 or 3, you can remove the wires. If you have installed Lesson 4, you can keep it.

Step 2: Install servo motor at the front of upper car chassis with 2pcs M2.2*8 Self Tapping Screws

Step 3: Install Ultrasonic Module to mount holder with 4pcs M1.5*8 screw and M1.5 nuts

Step 4: Install mount holder for Ultrasonic Module on servo motor with M2*4 Self Tapping screw

Step 5: Install Buzzer module at the back of upper chassis with 1pc M3 plastic screw, M3 plastic pillar and M3 plastic nut

Step 6: Connect SG90 servo motor, OSOYOO MODEL X motor driver module and OSOYOO Uart WiFi shield V1.3 as following grape:

Step 7: Connect ultrasonic module, Buzzer module with OSOYOO Uart WiFi shield V1.3 as below connection diagram

Step 8: Fix the screws on copper pillars to connect upper chassis to lower chassis if you remove these.


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 fromhttps://osoyoo.com/driver/v2smartcar-lesson5.zip , unzip the download zip file smartcar-lesson5.zip, you will see a folder called v2smartcar-lesson5 .

Step 3: Connect Arduino UNO to PC with USB cable, Open Arduino IDE -> click file -> click Open -> choose code “v2smartcar-lesson5.ino” in smartcar-lesson5 folder, load the code into arduino. (Notice: Please turn off battery power when your Robot is connected to Personal Computer or Laptop via USB cable)

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

Step 5: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 Ultrasonic sensor servo initial direction alignment

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.  See video from 7:4 to 8:10

Step 3) After you have changed the sensor direction, please run v2smartcar-lesson5.ino sketch again. Your car will begin to do obstacle avoidance driving.