![]() | ![]() | ![]() |
---|
Light-Seeking Obstacle-Avoiding Car
Abstract
The goal of our group project is to build a smart car that detects where the strongest light is coming from, follows it, and avoids any obstacle along the way. To lead the car, it is required to use a strong light source such as a focused flashlight in a dark room.
Introduction
The components needed to build such a car include:
-
Arduino Uno
-
The code will be uploaded to Arduino board and run infinitely.
-
-
Motor shield
-
Needed for providing power for the dc motors.
-
-
Ultrasonic distance sensor
-
Light sensitive resistor
-
-
Resistors
-
A resistor with proper value is put in series with the light sensor for the accurate reading from ADC on Arduino.
-
-
Servo motor * 2
-
One for light sensor and the other for distance sensor
-
-
Three- or four-wheel car
-
A three-wheel car is easier to turn to the exact angle, and we therefore chose it over the four-wheel car. The car uses two DC motors to move, and each motor can have a different speed.
-
-
Breadboard
-
Soldering tools
-
Wires
Design Process
To begin with, the car has to be able to move, so we installed independent power source on the car, which is the 6V DC battery pack in Fig. 1. It allows the car to move without being connected the computer. In fact, the power from the USB port is not enough to power the car.
The control of the car is easily achieved with the library for the motor shield. It allows three movement modes: Forward, Backward, and Release(Stop). The value range for speed is 150 – 255, and we set default speed to be 150. When we want the car to turn, one wheel will stop rotating while the other rotates at 150. It takes about 2.2 seconds for the car to turn 360 degrees, so we can very accurately turn the car to angle θ by setting its wheels to the speeds stated above, and let it stay in that mode for t seconds, where
In order to detect the direction of the strongest light source, we put a light sensor on the arm of the servo motor, and make it spin from 0 to 180 degrees continuously. For every degree that it covers, the Arduino will read the voltage across the light sensor. The lowest value indicates the strongest light. The program then remembers the value and makes the car turn to the exact angle.
While the car is doing all of this, it can run into an obstacle at any moment, because it by default assumes that there is nothing between the light source and itself. Therefore we put a distance sensor on another servo and make it spin from 0 to 180 degrees. This way, the car checks the distance of the closest object in front of it, and if it gets too close, then the car tries to go around it. There is another mode that allows the car to get out of a corner if it is stuck. This can happen sometimes when the car is too close to the obstacle and cannot turn in any direction. If that is case, then the car backs up for a certain distance and then re-scan its surrounding.
To successfully avoid obstacles with one attempt in most situations, the program has to get a good understanding of the environment. The servo motor spins from 0 to 180 degrees and checks the distance in that direction for every degree, so we end up with a 2D map the object outline in front of the car. In a generic scenario, it would look like the image below.
The car stops when L is shorter than a certain threshold 𝑙1. It then scans the left and right side, and records the angle θ when the distance is longer than another threshold 𝑙2 and
This guarantees that the car will have enough room to turn in most cases. Note that the car does have a width, so it actually needs to turn a little bit wider than θ to prevent its side from crashing into the obstacle. As for how far it goes before getting back to the normal mode and checking for light source, we give it an empirical distance because it does not need to stop exactly at the edge of the obstacle.
Algorithm
-
Begin
-
Setup
-
Infinite while loop:
-
Scan for distance
-
If the distance is too close ---> go around the obstacle Scan for the strongest light source
-
Determine the angle of the light source
-
Turn to the detected direction and go forward
-
-
End of while loop
-
End of program
Conclusion
We learned a lot from this project on both software and hardware. It is a great opportunity to design the entire algorithm and tune the electronics to the best performing condition. Now reflecting back on it, the hardest part is probably solving all the details. We knew what we wanted to achieve in the very beginning, but numerous unexpected issues and bugs came up after the general structure and code were finished. Debugging took us the longest time, and it is probably not as fun as the other parts, but in general we enjoyed the process of problem solving and improvising.


