MyRoboPathOpen Robotics Lab
Basic Robots Track #5 of 7
Est. 4 Hours
Budget: $26 - $38
Intermediate

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.

View Firmware on GitHub
Analog/Digital IR Array2x-5x TCRT5000 IR ModulesProportional SteeringPID ControlDifferential Drive

Bill of Materials (BOM) & Hardware Components

ComponentSpecificationsQtyApprox Cost
5-Channel TCRT5000 Infrared Reflectance Sensor Bar5 phototransistor pairs with onboard LM393 comparators and sensitivity pots1$4.50
Micro N20 High-Speed Metal Gearmotors (6V 600RPM)High-torque density brass gearboxes with silicone rubber tires2$8.50
TB6612FNG Dual MOSFET Motor DriverHigh-efficiency dual H-bridge with negligible voltage drop (<0.3V)1$4.00
Arduino Nano or ESP32 DevKitHigh-speed 1kHz control loop execution1$5.50
2S 7.4V 800mAh LiPo Battery & Buck ConverterLightweight high-discharge power source with regulated 5V rail1$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.

Figure 5: TCRT5000 5-channel sensor bar pinout, TB6612FNG motor driver connections, and PID control loop.
Figure 5: TCRT5000 5-channel sensor bar pinout, TB6612FNG motor driver connections, and PID control loop.Wiring Schematic

Step-by-Step Assembly & Configuration Tutorial

Follow each milestone step with photos, wiring checks, and testing procedures.

1

Mounting TCRT5000 Sensor Bar at Calibrated Height

Duration: 1 Hour

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.

Step 1: Mounting TCRT5000 IR sensor array at calibrated 5mm ground clearance.
Step 1: Mounting TCRT5000 IR sensor array at calibrated 5mm ground clearance.Step 1 Photo
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Infrared reflection follows the inverse-square law: mounting higher than 10mm causes severe signal drop, while mounting under 2mm risks bottoming out on floor seams.
2

Sensor Calibration & 5-Bit Positional Error Weighting

Duration: 1.5 Hours

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.

Step 2: Calibrating optical thresholds and 5-bit positional error bitmask.
Step 2: Calibrating optical thresholds and 5-bit positional error bitmask.Step 2 Photo
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Store `lastError` in memory: if all sensors read 0 (line lost on sharp hairpin turn), immediately pivot toward `lastError` to reacquire the track!
3

Implementing 1kHz PID Steering Control Loop

Duration: 1.5 Hours

Implement the Proportional-Derivative (PD) formula: `correction = (Kp * error) + (Kd * dError)`. Modulate left and right motor speeds dynamically in firmware.

Step 3: Closed-loop PID steering code implementation and track testing.
Step 3: Closed-loop PID steering code implementation and track testing.Step 3 Photo
Step Action Checklist:
  • 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.
Engineering & Tuning Tip: Avoid Integral gain (Ki) on basic line followers, as integral accumulation causes severe overshoot on high-speed straightaways.