High-Precision Line Follower
Construct a fast, high-precision line-tracking robot using a 5-channel TCRT5000 infrared reflectance array and tuned Proportional-Derivative (PD) steering.
Line followers are the direct foundation of Automated Guided Vehicles (AGVs) operating in modern fulfillment centers! This project teaches optical infrared reflectance sensing, digital comparator threshold calibration, weighted error calculations, and real-time Proportional-Derivative (PD) steering algorithms to navigate complex tracks, sharp 90° bends, and high-speed curves.
Bill of Materials (BOM) & Hardware Components
| Component | Specifications | Qty | Approx Cost |
|---|---|---|---|
| 5-Channel TCRT5000 Infrared Reflectance Sensor Bar | 5 phototransistor pairs with onboard LM393 comparators and sensitivity pots | 1 | $4.50 |
| Micro N20 High-Speed Metal Gearmotors (6V 600RPM) | High-torque density brass gearboxes with silicone rubber tires | 2 | $8.50 |
| TB6612FNG Dual MOSFET Motor Driver | High-efficiency dual H-bridge with negligible voltage drop (<0.3V) | 1 | $4.00 |
| Arduino Nano or ESP32 DevKit | High-speed 1kHz control loop execution | 1 | $5.50 |
| 2S 7.4V 800mAh LiPo Battery & Buck Converter | Lightweight high-discharge power source with regulated 5V rail | 1 | $9.50 |
Electrical & System Architecture
5 digital IR sensor outputs connect to Arduino pins D2, D4, D7, D8, D12. TB6612FNG driver receives PWM on D5/D6 and direction logic on D3/A0/A1/A2. Sensor bar is fixed exactly 5mm above the track surface.
Step-by-Step Assembly & Configuration Tutorial
Follow each milestone step with photos, wiring checks, and testing procedures.
Mounting TCRT5000 Sensor Bar at Calibrated Height
Mount the 5-channel IR sensor bar at the extreme front of the chassis. Use nylon standoffs and brass washers to adjust the sensor height to strictly 4mm - 7mm above the track surface.
- Mount the sensor bar completely parallel to the ground so all 5 phototransistors receive identical optical reflection.
- Position the sensor bar as far ahead of the drive wheels as possible to maximize look-ahead steering responsiveness.
- Construct a test track on white poster board using standard 19mm black electrical tape.
Sensor Calibration & 5-Bit Positional Error Weighting
Adjust the onboard sensitivity potentiometer for clean digital 1/0 transitions over white vs black. Map sensor combinations into weighted error values from -2 to +2.
- Rotate onboard trimmer until indicator LEDs light up ONLY when positioned directly over the black tape.
- Implement position formula: `error = (-2*S1) + (-1*S2) + (0*S3) + (1*S4) + (2*S5)`.
- Verify error = 0 when the center sensor (S3) is centered over the black line.
- Implement intermediate states (e.g. S2+S3 active -> error = -0.5) for 9-step precision.
Implementing 1kHz PID Steering Control Loop
Implement the Proportional-Derivative (PD) formula: `correction = (Kp * error) + (Kd * dError)`. Modulate left and right motor speeds dynamically in firmware.
- Calculate motor speeds: `Left_Speed = BaseSpeed + correction; Right_Speed = BaseSpeed - correction;`.
- Constrain motor outputs between 0 and 255 using `constrain()`.
- Tune Kp first: start with Kd=0, increase Kp until the robot tracks lines with gentle hunting oscillation.
- Add Kd to dampen oscillation and execute crisp, high-speed 90-degree corner turns.