For my embedded systems class this semester, our first project was to create a line following robot using an Arduino, two servos, and two IR sensors.
Demonstration:
https://www.youtube.com/watch?v=b374YOKX74I
Stability:
https://www.youtube.com/watch?v=3h2hCDh6TkI
In the videos above, I reset the robot to make sure the light adjustment was accurate. I then allowed the robot to scan the line for even better adjustment. Then I pressed the button to go to mode 1, which then started the motors. The first video shows a working demonstration and the second video shows how difficult it is for the robot to lose its place. While I did not show the robot failing to get back on the line, it is still possible and can be accomplished by smacking it hard enough to move the line out of its turn radius. That being said, the robot should not need to deal with those conditions in practice.
The robot itself is simply two continuous rotation servos, two IR sensors, a button, and an Arduino. The Arduino sketch comprises most of the complexity of the project. The Arduino program used to control the robot can be downloaded below. The program has 4 modules that run. First, a setting module watches for button presses and allows other modules to respond to different modes of operations set by the button. The second module is a thresholder that takes the analog sensor values, takes averages and stores the min and max values. Then the thresholder converts the analog values into a ‘1’ if the sensor detects the line and ‘0’ otherwise. The third module is the transition module, which pays attention to the change of the sensors and will output a value telling the other modules if the robot is moving left or right with respect to the line. The last module controls the motors. The motor is driven given the binary sensor values and the left/right value to determine which way it needs to move. The logic is designed to go forward when the left sensor is on the line and the right sensor is off the line. Any other combination will cause the robot to drive towards the line.
LineFollowingRobot.zip (File –> Download)
Future Improvements:
Most line following robots use a multitude of sensors to increase their ability to detect the line. As an Honor’s project, I will be using a camera instead. This camera is the OV7670 camera module that uses a parallel data port and a subprotocol to the I2C (TWI) protocol to manipulate settings. In the current stage of development, the camera operates at 2.5fps at a resolution of 176 x 144, which will give me the same resolution as if I had 25,344 IR sensors. The hardware implementation of the I2C protocol (Wire library) does not properly communicate with the camera (The speed of 100 kHz is too fast), so I created my own library to run I2C communication manually with a scalable speed. Using this library, the Arduino can communicate with the camera smoothly. Soon I will create an Arduino sketch to save the camera data to an SD card, and a Java program to interpret this raw data and format it into JPEG or BMP.
Stay tuned for more updates on this project.
