Lesson 4 Obstacle Avoidance Car
Lesson 4 Obstacle Avoidance Car
com
The joy of learning, is not just know how to control your car, but also know how to protect your car.
So, make your car far away from collision.
Learning parts:
Learn how to assemble the ultrasonic module
Be familiar with using steering
Learn about the principle of car avoidance
Use the program to make obstacle avoidance car come true
Preparations:
A car (with battery)
A USB cable
A suit of ultrasonic cradle head
Tips: If you have any questions or run into any problems during assembling and testing Smart Robot Car please feel free to contact us at
service@elegoo.com or euservice@elegoo.com (Europe customers).
Http://www.elegoo.com
Ⅰ. Connection
tips:Because our products have been corrected accurately when they are
manufactured, you can ignore the following step "Connection" if you don't remove
When assemble the ultrasonic sensor module holder, the servo should also be
STEP1: Connect the UNO to the computer and open the Servo_debug code file in the
Tips: If you have any questions or run into any problems during assembling and testing Smart Robot Car please feel free to contact us at
service@elegoo.com or euservice@elegoo.com (Europe customers).
Http://www.elegoo.com
STEP2: Select “Tool” --> ”Port” and “Board” in the Arduino IDE.
Tips: If you have any questions or run into any problems during assembling and testing Smart Robot Car please feel free to contact us at
service@elegoo.com or euservice@elegoo.com (Europe customers).
Http://www.elegoo.com
STEP3: Click the arrows button to upload the code to the UNO controller board.
After done uploading, the servo will rotate to 90 degrees and stationary.
the direction of 90 degree, it will rotate to left or right by 15 degree, which means the
Tips: If you have any questions or run into any problems during assembling and testing Smart Robot Car please feel free to contact us at
service@elegoo.com or euservice@elegoo.com (Europe customers).
Http://www.elegoo.com
2 Why does the micro servo is out of control and keeps rotating?
Use “myservo.attach(3,700,2400)” to command the micro servo to the angle degree which has a
range from 0 to 180. If it exceed the range, the micro servo won’t recognize this angle and will
keep rotating.
Ⅱ. Upload program
Because the program uses the library <servo.h>, so we need to install the library at first.
Open the Arduino software
Tips: If you have any questions or run into any problems during assembling and testing Smart Robot Car please feel free to contact us at
service@elegoo.com or euservice@elegoo.com (Europe customers).
Http://www.elegoo.com
Search servo and then install the newest version. The following picture shows that the Servo library is
already installed.
Tips: If you have any questions or run into any problems during assembling and testing Smart Robot Car please feel free to contact us at
service@elegoo.com or euservice@elegoo.com (Europe customers).
Http://www.elegoo.com
Connect the UNO controller board to the computer, open the code file in the path “\Lesson 4
Obstacle Avoidance Car\Obstacle_Avoidance_Car\Obstacle_Avoidance_Car.ino”.
Upload the program to the UNO board.
After uploading the program to the UNO control board, disconnect the cable, put the vehicle on the
ground and switch on the power supply.
You will see that the vehicle will move forward and the cloud platform keeps rotating to make the
distance measuring sensors operate continuously. If there are obstacles ahead, the cloud platform will
stop and the vehicle will change its direction to bypass the obstacle. After bypassing the obstacle, the
cloud platform will keep rotating again and the vehicle will also move on.
Ⅲ. Introduction of principle
Tips: If you have any questions or run into any problems during assembling and testing Smart Robot Car please feel free to contact us at
service@elegoo.com or euservice@elegoo.com (Europe customers).
Http://www.elegoo.com
Normally the servo has 3 controlling line: power supply, ground and sign.
The signal modulation chip in the servo receives signals from the controller board then the
servo will get the basic DC voltage. There is also a reference circuit inside the servo which will
produce a standard voltage. These two voltages will compare to each other and the difference
will be output. Then the motor chip will receive the difference and decide the rotational speed,
direction and angel. When there is no difference between the two voltages, the servo will stop.
To control the servo rotation, you need to make the time pulse to be about 20ms and the high
level pulse width to be about 0.5ms~2.5ms, which is consistent with the angle limited of the
servo.
Taking 180 angle servo for example, corresponding control relation is as below:
0.5ms 0 degree
1.0ms 45 degree
1.5ms 90 degree
Tips: If you have any questions or run into any problems during assembling and testing Smart Robot Car please feel free to contact us at
service@elegoo.com or euservice@elegoo.com (Europe customers).
Http://www.elegoo.com
Tips: If you have any questions or run into any problems during assembling and testing Smart Robot Car please feel free to contact us at
service@elegoo.com or euservice@elegoo.com (Europe customers).
Http://www.elegoo.com
Method of connecting lines: VCC, trig (the end of controlling), echo (the end of receiving), GND
(1)Apply IO port of TRIG to trigger ranging, give high level signal, at least 10us one time;
(2)The module sends 8 square waves of 40kz automatically, tests if there are signals returned
automatically;
(3)If there are signals received, the module will output a high level pulse through IO port of
ECHO, the duration time of high level pulse is the time between the wave sending and
receiving. So the module can know the distance according to the time.
Tips: If you have any questions or run into any problems during assembling and testing Smart Robot Car please feel free to contact us at
service@elegoo.com or euservice@elegoo.com (Europe customers).
Http://www.elegoo.com
Actual operation:
The Timing diagram is shown below. You only need to supply a short10uS pulse to the trigger
input to start the ranging, and then the module will send out an 8 cycle burst of ultrasound at
40 kHz and raise its echo. The Echo is a distance object that is pulse width and the range in
proportion .You can calculate the range through the time interval between sending trigger
signal and receiving echo signal. Formula: uS / 58 = centimeters or uS / 148 =inch; or: the
range = high level time * velocity (340M/S) / 2; we suggest to use over 60ms measurement
int Distance_test()
{ digitalWrite(Trig, LOW);
delayMicroseconds(2);
digitalWrite(Trig, HIGH);
delayMicroseconds(20);
digitalWrite(Trig, LOW);
Tips: If you have any questions or run into any problems during assembling and testing Smart Robot Car please feel free to contact us at
service@elegoo.com or euservice@elegoo.com (Europe customers).
Http://www.elegoo.com
Fdistance= Fdistance/58;
return (int)Fdistance;
Tips: If you have any questions or run into any problems during assembling and testing Smart Robot Car please feel free to contact us at
service@elegoo.com or euservice@elegoo.com (Europe customers).
Http://www.elegoo.com
From above picture, we can see that the principle of obstacle avoidance car is very simple. The
ultrasonic sensor module will detect the distance between the car and the obstacles again and
again and sending the data to the controller board, then the car will stop and rotate the servo
to detect the left side and right side. After compared the distance from the different side, the
car turn to the side which has longer distance and move forward. Then the ultrasonic sensor
Code preview:
http://www.elegoo.com
2019.7.15
Tips: If you have any questions or run into any problems during assembling and testing Smart Robot Car please feel free to contact us at
service@elegoo.com or euservice@elegoo.com (Europe customers).