top of page

Line Following Robot
This was a partner project for my robotics class. The objective was to build a robot capable of following a line using only a color sensor. Our robot was controlled using a Raspberry Pi and L289N motor drivers.

Mechanical Design
Our robot was designed in Onshape and is primarily made of lasercut acrylic parts. My partner had the idea for a Super Mario 64 star to fit with the Super Mario theme of our class. I made sure to include mounting locations for electronics in my design and also made acrylic washers to control the height of our caster wheel and color sensor. The motor mounts were 3D printed and bolted to our acrylic plate. The holes for the motor also served as a mounting location for our motor driver which was raised from the surface with brass standoffs.
Electronics & Wire Management
Our robot only had three electronic components: the Raspberry Pi, L289N motor driver, and the color sensor. Because we had a simple system I chose use a protoboard for our color sensor. This helped to keep our system compact so it could easily fit in the space between our acrylic stars.
Steering System: Part I
I wrote a simple function for steering that my partner was able to call in the body of our code to steer the robot. The function takes two PWM values for the left and right motors, as well as a duration of time that the motors should be on for. Before the function is called, the pins for the motors are set high and the PWM is started but set to zero.
Debugging
We previously had the steering function set the motor pins high and low to turn the motors on and off. When steer() was called in rapid succession in the body of our code, this would cause one motor to stall and make a beeping noise. Once the code was adjusted to control the PWM value and not the pin setting, our motor stall issue was fixed.

Steer Function
Line Following Code
Because we only used one color sensor, my partner and I implemented a wobble method to keep our robot on the line. We had our color sensor slightly offset to the right of the motor, and the default was to start by turning left if the robot lost the line. It would attempt two turns to the left, checking to see if it found the line in the middle, and if it did not find a line, complete four turns right. Additionally, we found that the values changed the most when we had it track the colors it wasn't meant to follow. If the robot is meant to follow a red line and veers off into the white paper, we would expect the blue and green readings to spike up. When this spike occurs, the robot begins its wobble to relocate the line.
Calibration
Once we placed our robot on the line and started our code, the first thing that happens is calibration. This allows the robot to work in multiple different light settings because the calibration happens every time it runs. It also has a waiting period so that we can check the printed calibration readings are sensible.
Part II: Using a camera
For the second part of this project, we used a camera to follow a line. This provided a lot more information, and we implemented a PID controller once we had a more accurate read on error. The more trustworthy data also lead us to reduce our wait time in between steering. Using the color sensor, we would pause after every movement to collect data and average the readings to eliminate outliers. This had a significant effect on the max speed of the line following. Using the camera we were able to eliminate the sleep time in our steering function and call steering commands continuously.
Calibration
To clarify the data, we used a grayscale filter on the camera, eliminating need for calibration of color. We did encounter issues with the camera identifying other lines, and we cropped our image to counteract this problem. The data was also run through a gaussian filter so that the edges of the line were easily identifiable.
Mechanical Updates
We added standoffs to our system to increase the height of the camera, and attached the camera to the tip of the star with a piece of tape. Additionally, we created new wheels that had a slot to hold rubber bands. This helped to increase wheel traction without the rubber bands slipping off.

Purple Line
Red Line
Black Line
bottom of page