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

In this project, we will use obstacle sensor(ultrasonic distance detector) to detect obstacles ,avoid collision and auto-drive.

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

Step 1:Remove screws on copper pillars and install servo motor at the front of car chassis with 2pcs M2.2*8 Self Tapping Screws.

Step 2:Install bracket (from servo motor package) on mount holder for Ultrasonic Module with 2pcs M1.5*4 Self Tapping Screws

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

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

Step 5:If you have already completed wire connection installation in Lesson 21 , just keep it as is.

Then Connect SG90 servo motor to OSOYOO to the D3 port of the Magic I/O shield as following graph.

Step 6:Then connect the Ultrasonic module sensor to the D7D8 port of the Magic I/O shield with a 4-pin PNP cable as below:

Notice: Shut off your battery or Unplug your power adapter when upload sketch code to Arduino.

After above installations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should turn on.

Now you can download the sketch code directly from following link:

https://osoyoo.info/upload/lesson28.zip

Unzip the file, double click the lesson28.ino to open Arduino IDE and upload the code to the Arduino IDE

Adjust the Ultrasonic Sensor direction:
After the code is loaded into robot car,  unplug the USB cable from the UNO board and turn on the power switch on the Magic I/O board. Then the ultrasonic sensor will rotate to face the straight forward direction for 2 seconds. If the Ultrasonic sensor is not facing the front position, please turn off the power. Please use a screw driver to adjust the ultrasonic sensor direction and make it facing straight ahead , then turn on the power again  and during the early 5 seconds, the sensor should be facing front direction.

After the 5 seconds , the robot car will start to drive  and change direction to avoid obstacles automatically.