Autonomous line-following robot with PID control algorithm
DUTH — Department of Informatics | Embedded Systems | Spring 2026
This project involves the design and implementation of a fully autonomous robotic vehicle that follows a black line on a white surface. The system uses TCRT5000 infrared sensors and a PID control algorithm to dynamically correct its path in real time, without any human intervention.
- Autonomous line tracking (straight paths & curves)
- PID controller for smooth and stable navigation
- Search mode — automatic line recovery when lost
- Stop condition — automatic halt at the end of the track
- Independent motor speed control via PWM
| Component | Description | Qty |
|---|---|---|
| Maker Pi RP2040 | Main microcontroller board (RP2040 @ 133 MHz) | 1 |
| TCRT5000 | Analog infrared sensor for line detection | 3 |
| N20 DC Motor 6V/500rpm | Micro DC gear motor | 2 |
| N20 Rubber Wheel 43mm | Rubber wheels for traction | 2 |
| Li-Po 7.4V 1200mAh | Rechargeable battery pack | 1 |
| UBEC 5V | Voltage regulator (7.4V → 5V) | 1 |
| Plywood 3mm | Chassis 12.7×12.5 cm | — |
Total build cost: ~€40.19
┌─────────────────────────────────────────┐
│ RP2040 (133MHz) │
│ │
│ TCRT5000 ──► Sensor Read │
│ (GPIO 26,27,28) │ │
│ ▼ │
│ Error Calculation │
│ (left / center / right) │
│ │ │
│ ▼ │
│ PID Controller │
│ (Kp · e + Ki · ∫e + Kd · Δe) │
│ │ │
│ ▼ │
│ PWM Output (Motor L / R) │
└─────────────────────────────────────────┘
-
Normal operation: Sensors read the line → position error is calculated → PID adjusts the motors via PWM.
-
Search mode: If the line is lost (all sensors read white) → the robot rotates toward the last known direction until the line is found again.
-
Stop condition: If all sensors simultaneously detect black → the robot stops completely and PID variables are reset.
// PID control
float error = get_error(b_l, b_c, b_r);
set_speeds(BASE_SPEED + correction,
BASE_SPEED - correction);
// Search mode
if (last_seen == "left")
set_speeds(0, SEARCH_SPEED);
// Stop condition
if (all_black)
motor_stop();line-follower/
├── src/
│ └── LineFollowerCode.ino # Main source code (C++/ArduinoIDE)
├── LineFollowerPictures/
| ├── CompetionStages.png #Photos from the three stages
│ ├── Photo.jpg # Line Follower Photo
│ ├── PhotoBottomView.jpg #Photo from the bottom view
│ ├── PhotoTopView.jpg # Photo from the top view
├── LICENSE
└── README.md
- Flash the code onto the Maker Pi RP2040 board (using Arduino IDE).
- Calibrate the TCRT5000 sensors via the onboard potentiometers according to ambient lighting conditions and connect the to the corresponding pins on the board ADC(26,27,28)
- Place the robot on the track and power on.
- Reliable line tracking on both straight segments and curves
- Effective line recovery mechanism in search mode
- Correct activation of stop condition at track end
- Attention: Re-calibration required under varying lighting conditions
- Increase sensor count (3 → 5+) for faster response
- Use SPI/I2C communication for reduced sensor read latency
- Implement automatic calibration at startup
© 2026 Group 2 - Democritus University of Thrace. All rights reserved.



