Skip to content
Build GuidesFebruary 20, 2026Foundational

Build a Line-Following Robot from Scratch

RTJ Editor
RoboTechJournal Contributor
Build a Line-Following Robot from Scratch
ContentsThe Hardware

A line-following robot is the classic "Hello World" of autonomous robotics. While simple to build, making one run quickly and smoothly requires understanding control theory.

Some articles include recommended robotics gear. We only suggest products we genuinely believe are useful.

Explore robotics deals

The Hardware

You will need a chassis, two DC gear motors, an L298N or TB6612FNG motor driver, a microcontroller (see our recommendations), and an IR sensor array (e.g., QTR-8RC). The sensor array is critical; using 8 sensors provides much better resolution than a basic 2-sensor setup.

The Problem with Bang-Bang Control

The simplest code logic is: "If the left sensor sees the line, turn left. If the right sensor sees the line, turn right." This is called bang-bang control, and it results in a robot that violently zig-zags down the line.

Implementing PID Control

To achieve smooth, high-speed tracking, we use a Proportional-Integral-Derivative (PID) controller. The PID algorithm calculates an error value (how far off the center of the line we are) and adjusts the motor speeds proportionally.

  • Proportional (P): Steers harder the further away from the center you are.
  • Derivative (D): Looks at how fast the error is changing, applying a dampening effect to prevent overshoot and oscillation.
  • Integral (I): Corrects for small, persistent errors over time (rarely needed for line followers).

Start tuning by setting I and D to zero. Increase P until the robot tracks the line but oscillates. Then, slowly increase D until the oscillation stops.

Recommended Gear

L298N Dual H-Bridge Motor DriverRecommended

The standard motor driver for beginner robotics. Controls two DC motors independently with PWM speed and direction — works directly with Arduino or ESP32.

$6–$12View on Amazon
Pololu QTR-8RC Reflectance Sensor Array

8-channel IR reflectance sensor with a dedicated Arduino library. Provides the high resolution needed for smooth PID line tracking.

$10–$14View on Amazon
Elegoo 4WD Robot Car Chassis Kit

Acrylic 4-wheel drive chassis with DC gear motors, wheels, and battery holder. A solid, low-cost foundation for a first line-following build.

$15–$22View on Amazon

Affiliate disclosure: RoboTechJournal participates in the Amazon Services LLC Associates Program and other affiliate programs. We may earn a small commission when you buy through our links — at no extra cost to you. We only recommend products we have researched or used.

More from Build Guides

Configuring ROS 2 Nav2 Costmaps: Inflation, Footprints, and Clearing for Constrained Corridors
Build GuidesSep 21, 2026Intermediate

Configuring ROS 2 Nav2 Costmaps: Inflation, Footprints, and Clearing for Constrained Corridors

Tune ROS 2 Nav2 costmaps for constrained corridors. Define footprints, balance inflation costs, clear ghost obstacles, and validate safe navigation in RViz.

Fusing IMU, Wheel Odometry, and GPS with ROS 2 robot_localization: A Dual EKF Guide
Build GuidesSep 19, 2026Intermediate

Fusing IMU, Wheel Odometry, and GPS with ROS 2 robot_localization: A Dual EKF Guide

Fuse wheel odometry, IMU, and GPS with robot_localization. Configure dual EKFs, heading conventions, navsat transforms, covariance, and TF ownership.

Underwater and Swimming Robot Kits: A Beginner's Guide
Build GuidesJul 22, 2026Foundational

Underwater and Swimming Robot Kits: A Beginner's Guide

What's different about underwater robot builds, what to look for in a beginner ROV kit, and the mistakes that sink most first attempts.