This tutorial upgrades your robot car into a real line follower using an IR reflectance sensor array. You’ll calibrate sensors, verify wiring, then run a PID loop that keeps the robot centered on a black tape line.
Tip: Start with 3 sensors (L/C/R). It’s simpler and works great.
Wiring diagram:
This diagram shows a typical 3-sensor setup (LEFT / CENTER / RIGHT) wired to Raspberry Pi GPIO.
If you use a 5-sensor array, wire the extra sensors to free GPIO pins and update the pin list in
code/calibrate.py and code/line_following.py.
Most IR line sensors have: VCC, GND, and OUT (digital) or AOUT (analog).
Important: If your sensor outputs 5V logic, level-shift to 3.3V before feeding the Pi.
Folder: code/ (included in this package)
This is a clean starter that assumes you already have motor control from Tutorial 01. Replace the placeholder motor driver class with your actual pins/driver.
Option A — TCRT5000 digital modules (3 sensors):
Use this if your sensors have a digital OUT pin. Make sure the OUT signal is 3.3V-safe for the Pi.
Option B — Analog line sensor array (QTR / similar) via MCP3008:
Use this if your sensor array outputs analog values. You’ll read it through an MCP3008 ADC over SPI. If you tell me the exact array model, I’ll adapt the code to match it.
IR Reflectance Sensor Basics: Explains how IR sensors detect black vs white surfaces, how reflectance works, and why these sensors are ideal for line-following robots.
PID for Robots: Walks through proportional and derivative tuning for smooth line following, showing how PID stabilizes steering in real robots.
Full Build Walkthrough: Shows sensor mounting, wiring, code logic, testing, and real-world troubleshooting for a complete line-following robot.
Add these to your page once you pick the exact videos you want:
If you send me the 3 YouTube links you want, I’ll drop them in with captions and timestamps.