I.Objective
II.Parts and Devices
III.Hardware Installation
IV.Software Installation
VI.How to play

Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES ここでご購入を!


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.

Download PDF Tutorials:https://osoyoo.com/manual/2021006600.pdf

OSOYOO Robot car installation video: https://osoyoo.com/manual/2021006600.html


OSOYOO Mecanum wheels robotic car chassis x1
OSOYOO Wheels and motors x4 (left-wheels x2/right-wheels x2)
OSOYOO Mega2560 board fully compatible with Arduino UNO/Mega2560 x1
OSOYOO Uart WIFI shield x1
OSOYOO Model Y driver board x1
OSOYOO Voltage meter x1
OSOYOO MG90 servo motor x 1
OSOYOO Ultrasonic sensor module x1
OSOYOO Mount holder x1
OSOYOO Battery box x1
OSOYOO 3pin female to female jumper wire x1
OSOYOO 6pin male to female jumper wire x2
OSOYOO 10pin male to female jumper wire x1
OSOYOO 2 pin XH.25 female to female x1
18650 Batteries(3.7V) x2
Battery charger x1

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

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

When placing the ultrasonic underneath,as the self tapping screws screws easily strip.
A.Support the motor from underneath,as the self tapping screws easily strip.
B.Do not insert the screw until after the alignment process.

3)Please keep all lesson 1 connections same as it is.Before connecting wires, make sure that you have connect SG90 servo motor to model Y board and OSOYOO uart wifi shield as follows.

(Note: You need split 1 pcs of male-to-female jumper wires from our 10-pc jumper wire bundle. Any color from the bundle will be ok. The rest of wires are as spare parts for potential broken or damaged wires.)

4)Connect ultrasonic module with OSOYOO Uart WiFi shield 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/mecanum_acrylic_chassis_v2/mc-lesson2.zip, unzip the download zip file mc-lesson2.zip, you will see a folder called mc-lesson2.zip.

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

Step 4: Choose MEGA2560 board as the board type and correct port for your project as following picture, 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 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 no need adjust sensor position anymore. Just wait 3 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 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.