Β
πππΏ ππππ ππππππππ ππππ πΌπΎπΎπππΌπΎπ πΌππΏ πππππΏ πππΏπ W

01 Overview
The PID Line Follower Robot with Accuracy and Speed Modes is an autonomous mobile robot capable of detecting and following a predefined path using a QTR-8RC Reflectance Sensor Array, an Arduino Uno, and a PID (ProportionalβIntegralβDerivative) control algorithm. Unlike conventional line follower robots that rely on simple left-right decisions, this project continuously calculates the robotβs position relative to the line and dynamically adjusts the speed of each motor to achieve smooth, stable, and accurate navigation.
The robot features two selectable operating profiles: Accuracy Mode and Speed Mode. Accuracy Mode is optimized for precise line tracking by using conservative motor speeds and smoother PID corrections, making it suitable for tracks with sharp turns, narrow curves, and complex layouts. Speed Mode is designed for high-performance operation by increasing the robotβs base speed and applying more responsive control, allowing faster lap times on tracks with long straight sections and gradual curves.Β Users can switch between these two modes through a dedicated hardware switch without modifying or re-uploading the program.
This project demonstrates the practical implementation of embedded systems, sensor integration, motor control, and feedback control principles. It also provides an excellent platform for learning autonomous robotics, PID tuning, and real-time control systems while serving as a competitive line follower robot for educational demonstrations and robotics competitions.
Project Use Case
This project is intended for students, educators, and robotics enthusiasts who want to understand the fundamentals of autonomous mobile robots and PID-based control systems. It can be used in robotics laboratories, engineering courses, embedded systems projects, and robotics competitions where reliable and efficient line tracking is required. The dual operating modes also make the robot suitable for experimenting with different PID tuning profiles and evaluating the balance between tracking accuracy and operating speed.
02 Hardware and Software Components
Gather everything below before you start. This is your checklist - names, models, and versions only.
Hardware Components
| PHOTO | Component | Description |
|---|---|---|
![]() |
Β Β Arduino Uno R3 | Main microcontroller responsible for processing sensor data and executing the PID algorithm. |
![]() |
Ardumoto Dual Motor Driver Shield | Controls the direction and speed of the left and right DC motors. |
![]() |
QTR8-RC Line Sensor | Detects the position of the black line for real-time navigation. |
![]() |
12V DC Gear Motors | Provide propulsion for the robot. |
![]() |
High Grip Silicone SLT20 Wheels | Improve traction and stability while following the track. |
![]() |
Dupont Jumper Wires | Flexible wires used to connect electronic components and Arduino pins, providing reliable signal and power connections during prototyping without soldering. |
![]() |
Β 18650 Li-Ion Battery 3.7V 2200mAh |
Supplies power to the Arduino and motors. |
![]() |
18650 Battery holder/case plastic for 3.7V Li-Ion battery | Holds and powers the batteries securely. |
![]() |
Mini Switch | Used to select between Accuracy Mode and Speed Mode. |
![]() |
Mini Plastic Caster Wheel Pair | Provides balance and smooth support for the robot while moving. |
Software Tools
| Software | Version / Details |
|---|---|
| Arduino IDE | Verson 2.3.8 |
| QTRsensor Library | Version 4.0.0 |
Project FilesΒ
All required files are available in the project repository. Download the repository before proceeding to the Software Setup section.
| FILE | DESCRIPTION |
|---|---|
| QTRSensors.hΒ | Library used to interface with the QTR-8RC sensor array for line detection and sensor calibration. |
03Β Hardware Wiring andΒ Setup
Wire the components to the board using the tables below.
Schematic Diagram

Assembly Instructions
- Assemble the robot chassis according to the kit instructions and securely attach the DC gear motors.
- Install the wheels onto the motor shafts and attach the mini caster wheel to the front or rear of the chassis.
- Mount the Arduino Uno and Ardumoto Motor Driver Shield onto the chassis using spacers or standoffs.
- Position the QTR-8RC sensor array at the front of the robot, approximately 3β5 mm above the track surface for optimal line detection.
- Connect the QTR-8RC sensor array, motor driver, speed mode switch, and other components to the Arduino using the specified wiring diagram.
- Install the battery holder securely on the chassis and connect it to the power input of the robot.
- Verify that all electrical connections are correct and firmly attached before powering on the system.
-
Upload the program to the Arduino Uno, calibrate the sensors, and test the robot on a line-following track.
04Β Software Setup
Follow these steps in order. Do not skip any step.
Download this first before proceeding.
Step 1: Install the Arduino IDE
- Download and install the Arduino IDE.
- Launch the Arduino IDE after installation.
- Connect the Arduino Uno to your computer using a USB cable
Step 2: Board Settings
Use exactly these settings in your IDE. Wrong settings will cause upload failures.
| Setting | Value |
|---|---|
| Board | Arduino Uno |
| Baud Rate | 9600 |
| PortΒ | Select the detectedΒ COM Port |
Step 3: Install Libraries
Install the following libraries via the Library Manager:
- QTRsensor by Pololu
05Β Code
Copy each file below into the correct location as described in the Software Setup section. Read the Code Breakdown section to understand what each part does.
#include <QTRSensors.h>
#define LPWM 3
#define RPWM 11
#define LDIR 12
#define RDIR 13
#define SPEED_SWITCH 2
const uint8_t S1 = A0;
const uint8_t S2 = A1;
const uint8_t S3 = A2;
const uint8_t S4 = A3;
const uint8_t S5 = A4;
const uint8_t S6 = A5;
const uint8_t S7 = 4;
const uint8_t S8 = 5;
QTRSensors qtr;
const uint8_t SensorCount = 8;
uint16_t sensorValues[SensorCount];
float Kp = 0.18;
float Ki = 0.0;
float Kd = 1.8;
int baseSpeed = 250;
int maxSpeed = 200;
int lastError = 0;
long integral = 0;
void setup() {
Serial.begin(9600);
qtr.setTypeRC();
qtr.setSensorPins((const uint8_t[]){
S1, S2, S3, S4,
S5, S6, S7, S8
}, SensorCount);
pinMode(LPWM, OUTPUT);
pinMode(RPWM, OUTPUT);
pinMode(LDIR, OUTPUT);
pinMode(RDIR, OUTPUT);
pinMode(SPEED_SWITCH, INPUT_PULLUP);
Serial.println("Calibrating...");
for (int i = 0; i < 300; i++) {
qtr.calibrate();
delay(5);
}
Serial.println("READY");
}
void loop() {
//==========================
// SPEED MODE
//==========================
if (digitalRead(SPEED_SWITCH) == LOW) {
Kp = 0.30;
Ki = 0.0;
Kd = 3.2;
} else {
Kp = 0.30;
Ki = 0.0;
Kd = 2.0;
}
uint16_t position = qtr.readLineBlack(sensorValues);
int error = position - 3500;
// Deadband
if (abs(error) < 25)
error = 0;
//==========================
//==========================
// ADAPTIVE SPEED
//==========================
if (digitalRead(SPEED_SWITCH) == LOW) {
// FAST MODE (Max = 200)
if (abs(error) < 150)
baseSpeed = 250;
else if (abs(error) < 400)
baseSpeed = 180;
else if (abs(error) < 800)
baseSpeed = 140;
else
baseSpeed = 90;
} else {
// NORMAL MODE (Max = 100)
if (abs(error) < 100)
baseSpeed = 100;
else if (abs(error) < 300)
baseSpeed = 90;
else if (abs(error) < 700)
baseSpeed = 80;
else if (abs(error) < 1200)
baseSpeed = 70;
else
baseSpeed = 60;
}
integral += error;
integral = constrain(integral, -3000, 3000);
int derivative = error - lastError;
int correction =
(Kp * error) +
(Ki * integral) +
(Kd * derivative);
correction = constrain(correction, -140, 140);
lastError = error;
int leftSpeed = baseSpeed + correction;
int rightSpeed = baseSpeed - correction;
// Extra slowdown habang lumiliko
if (abs(error) > 800) {
leftSpeed -= 40;
rightSpeed -= 40;
}
leftSpeed = constrain(leftSpeed, 0, 250);
rightSpeed = constrain(rightSpeed, 0, 250);
digitalWrite(LDIR, HIGH);
digitalWrite(RDIR, HIGH);
analogWrite(LPWM, leftSpeed);
analogWrite(RPWM, rightSpeed);
}
06Β Code Breakdown
Here is what each part of the code does. Read this after uploading.
Libraries
| Library | Purpose |
|---|---|
|
Β QTRSensors.h |
Provides functions for initializing, calibrating, and reading the QTR-8RC reflectance sensor array, enabling accurate line detection for the PID controller.
|
Key Functions
setup()
Initializes the Arduino, configures the motor and sensor pins, sets the speed mode switch, and calibrates the QTR-8RC sensor array before operation.
loop()
Continuously reads the line position, selects the operating mode, computes the PID correction, adjusts the motor speeds, and drives the robot along the line.
qtr.calibrate()Β
Collects sensor readings during startup to improve the accuracy of line detection under different lighting conditions.
qtr.readLineBlack()Β
Reads the QTR-8RC sensor array and calculates the position of the black line used by the PID controller.
PID CalculationΒ
Calculates the proportional, integral, and derivative terms to determine the correction value needed to keep the robot centered on the line.
ADOPTIVE SPEED CONTROLS
Automatically adjusts the robotβs base speed according to the tracking error, allowing higher speeds on straight paths and slower speeds during turns.
MODE SELECTION
Allows the user to switch between Accuracy Mode for stable tracking and Speed Mode for faster operation using the hardware switch.
General Program Workflow
- Initialize the Arduino, sensors, and motor driver, then calibrate the QTR-8RC sensor array.
- Read the line position, calculate the PID correction, and determine the appropriate motor speeds based on the selected operating mode.
- Drive the motors continuously while updating sensor readings and PID calculations to maintain accurate line tracking.
07Β Testing and Calibration
After uploading the code to your ESP32 and flashing the HMI display UI, verify each of the following tests to confirm the radar system is working correctly.
Sensor Calibration
Move the robot over the black line and white background during startup to allow the QTR-8RC sensor array to calibrate correctly.
Speed Mode Test
Switch between Accuracy Mode and Speed Mode and verify that the robot changes its operating behavior accordingly.
Line Following Test
Place the robot on the track and confirm that it follows the line smoothly without excessive oscillation or losing the path.
Curve Performance Test
Observe the robot while navigating wide and sharp curves. It should slow down during turns and quickly recover to the center of the line.
08Β System Demonstration
Video Demonstration
This video demonstrates the complete assembly of the PID Line Follower Robot, including the installation of all hardware components and wiring connections also this video compares the lap time performance of the robot in Accuracy Mode and Speed Mode on the same track.
09Β Conclusion
Possible Improvements and Future Enhancements
- Add Bluetooth or Wi-Fi for wireless PID tuning.
- Integrate an OLED display for real-time sensor and PID monitoring.
- Implement automatic intersection detection and maze-solving capabilities.
10Β References
- Β I made a SUPER FAST Line Follower Robot Using PID! By Shyam Ravi
11Β Project Authors
- Mikyla P. Montana
-
Jonna Kayzher S. Apellido
Β










