← Back to Projects

🏎 Line Following Car

A TI-RSLK robotics project using an 8-sensor array and a tuned PID controller to follow a track, complete a 180-degree turn, and return to the starting position as quickly as possible.
TI-RSLK
PID Control
Arduino IDE
Sensor Arrays
Motor Control
Robotics
View Code on GitHub ↗

Overview

This project used the TI-RSLK robotics platform to build and tune an autonomous line-following car. The car used an array of eight sensors underneath the chassis to detect a black line on paper and continuously estimate its position relative to the track.

My partner and I programmed the control logic in the Arduino IDE and tuned a PID controller to adjust the left and right wheel motors. The goal was to complete the track, perform a full 180-degree spin, and return to the starting position as quickly as possible without derailing.

Our build achieved the fastest completion time in our cohort for this track.

System Diagram

8-Sensor Array Line position PID Controller Arduino IDE Left Motor Right Motor Track

How It Worked

Technical Breakdown

The key challenge was balancing speed and stability. If the car moved too slowly, the run time was not competitive. If it moved too quickly, the controller could overshoot the line and derail. We tuned the PID constants to make the car respond quickly to errors while avoiding excessive oscillation.

The proportional term handled immediate correction, the derivative term helped reduce overshoot, and the final motor outputs controlled how aggressively each wheel adjusted to keep the robot aligned with the track.

PID Control Implementation

The controller continuously computes the error between the desired line position, or center of the sensor array, and the measured position. A PID controller generates a correction term that adjusts the motor speeds to keep the robot aligned with the track.

// PID constants, tuned experimentally
float kp = 0.6;
float ki = 0.02;
float kd = 1.2;

float error = 0;
float previousError = 0;
float integral = 0;

int baseSpeed = 120;

void loop() {
  int position = readLineSensors();
  int target = 3500;

  error = target - position;

  integral += error;
  float derivative = error - previousError;

  float correction = (kp * error) + (ki * integral) + (kd * derivative);

  int leftSpeed  = baseSpeed - correction;
  int rightSpeed = baseSpeed + correction;

  setMotorSpeeds(leftSpeed, rightSpeed);

  previousError = error;
}

The proportional term reacts to current error, the integral term compensates for accumulated bias, and the derivative term dampens oscillations. Careful tuning of these gains allowed the robot to move aggressively while remaining stable on sharp turns.

Results & Learnings

Reflection

This project was one of my first experiences seeing control theory work in a real physical system. It showed me how small changes in software parameters could dramatically affect hardware behavior, and it helped build my interest in embedded systems, robotics, and feedback control.

← Back to Projects