|Buy from US||Buy from UK||Buy from DE||Buy from IT||Buy from FR||Buy from ES||Buy from JP|
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.
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).
Step 2: Remove screws on copper pillars and install servo motor at the front of upper car chassis with 2pcs M2.2*8 Self Tapping Screws
Step 3:Install bracket (from servo motor package) on mount holder for Ultrasonic Module with 2pcs M1.5*4 Self Tapping Screws. (If you get mount holder which looks like cat’s head shape, please skip this step)
Step 4: Install Ultrasonic Module to mount holder with 4pcs M1.4*8 screw and M1.4 nuts
Step 5: Install mount holder for Ultrasonic Module on servo motor with M2*4 Self Tapping screw (Please note: please upload code to adjust servo motor direction before fixing this screw)
Step 6: Install Buzzer module at the back of upper chassis with 1pc M2.5 plastic screw, M2.5 plastic pillar and M2.5 plastic nut
Step 7: Connect SG90 servo motor, OSOYOO MODEL X motor driver module and OSOYOO basic board as following graph
Step 8: Connect ultrasonic module with OSOYOO basic board as below connection diagram
Step 9: Connect Buzzer module with OSOYOO basic board as below connection diagram
Step 10: Fix the screws on copper pillars to connect upper chassis to lower chassis.
|Download Arduin IDE here:
|7 zip is a free zip
utility that un-zips zip files
|Download 7zip here for free
Step 1: Install latest Arduin IDE (If you have Arduin IDE version after 1.1.16, please skip this step). Download Arduin 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 OSOYOO Basic board to PC with USB cable, Open Arduin IDE -> click file -> click Open -> choose code “v2smartcar-lesson5.ino” in smartcar-lesson5 folder, load the code into arduin. (Notice: Shut off your battery or Unplug your power adapter when upload sketch code to Arduin.)
Step 4: Choose corresponding board/port for your project,upload the sketch to the board.
Step 5:Ultrasonic sensor servo initial direction alignment(See above video from 7:02 to 7:35)
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
Is there an easy way to align my Ultrasonic sensor to make it facing front?
Step 1) Download https://osoyoo.com/driver/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:05 to 7:30
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.
DownLoad Url osoyoo.com
You must be logged in to post a comment.
Hi! i was just wondering when you first turn it on without any of the Arduino installed, should the buzzer module be making loud beeping noises?
When I power the UNO board (both with battery and USB cable), the buzzer is making loud beeping noises. If you upload the sketch, the buzzer will make sound accoridng to the sketch. If you don’t want to listen the buzzer noises, you can remove the wires on buzzer.
I was wondering why my sensor doesn’t turn around and why I don’t have holes in the ultrasonic mount
1. If my ultrasonic sensor doesn’t turn around, please check the connection of servo motor and you need to connect a S pin of model X to D9 of UNO R3 board.
2. As we upgrad the ultrasonic mount, and you just need to install the ultrasonic mount to servo motor and fix a M2*4 screws, you needn’t to install a blade on ultrasonic mount
Is it possible to use the ultrasonic sensor obstacle avoidance with line tracking IR sensors project?
Do you mean you want ultrasonic sensor and link tracking work together?
If so, you can follow our lesson 6 sample project.
I want the car to be able to go on a line track (lesson 4) but if there’s obstacles on the track, it will go away from it (lesson 5) Sorry late reply.
Lesson6 control the car work line following and obstacle avoidacne: https://osoyoo.com/2019/03/03/osoyoo-v2-robot-car-lesson-6-use-wifi-to-control-an-iot-robot-car/.
If you want the car follow the line and then when the car see the obstacle, the car will stop or change the direction, there is no sample code for this, but I think you can try to program for this.
mon outil blanc ne rentre pas dans le trou pour le capteur a ultrason et je ne peu pas visser l’outil blanc…
comment puis je faire ?
The mount holder for Ultrasonic Module is improved, and you needn’t to install the white bracket. You can install the holder on servo motor directly.
If you need image about the installation, please contact with my email address: [email protected].
I don’t quite understand how we are suppose to do the wiring for step 7: Connect SG90 servo motor, OSOYOO MODEL X motor driver module and OSOYOO UNO board as following graph. can you simplify it? what do we do with the obstacle sensor wires?
Hello, you need to connect ENA of model X board to D3 of UNO board, IN1 to D12, IN2 to D11, IN3 to D7, IN4 to D8, ENB to D6, S (under IN1) to D9.
The pins of SG90 are blown color for GND, Red color for VCC, Orange color for signal. Please connect the three pins(blown-red-orange) of SG90 to GND-5V-S of model X board.
what do I do with the D3 pin?
Is it possible to speed up the car’s parameters directly in the code? Like for example, can you edit how fast the servo motor rotates the ultrasonic sensor. If so, what lines in the code can you do that?
You can adjust 31 to 35 lines of speed parameters to change the speed of operation, we choose the 180-degree servo to control the ultrasonic rotation, can only adjust the angle, can not change the speed
Where in the code can I adjust the angle so that it’s not fully 180 degrees? Like for example if I wanted only 90 degrees?