Robot behavior
- Read a black line with three to five IR sensors.
- Estimate whether the line is left, centered, or right.
- Adjust each motor continuously to stay centered.
Turn your Raspberry Pi robot car into a smooth, accurate line follower. Mount and calibrate IR sensors, verify every connection, and tune a Python PID loop that keeps the robot centered on the track.

Place the sensor array low, centered, and ahead of the wheels.
Test every sensor over the floor and line before driving.
Record light and dark readings and choose stable thresholds.
Confirm left and right motor directions match the code.
Raise P gradually, add D to reduce weaving, and use I sparingly.
python3 calibrate.py python3 test_sensors.py python3 line_following.py
Use three separate sensors with digital DO/OUT pins: LEFT → GPIO 17, CENTER → GPIO 27, and RIGHT → GPIO 22.
Use this for a QTR-style analog array. The MCP3008 converts analog readings for the Raspberry Pi over SPI.
See how sensors distinguish a dark line from a light floor.
Learn how proportional and derivative control steady steering.
Follow mounting, wiring, testing, and troubleshooting.
Save the printable guide or return to the Academy for your next build.