How to Build an Arduino Line Follower Robot (LFR): Step-by-Step Assembly Guide
A complete visual walkthrough covering chassis preparation, BO motor mounting, IR sensor alignment, wiring architecture, and track testing.
A Line Follower Robot (LFR) is an autonomous mobile robot engineered to detect and follow a visual path—typically a black line on a white surface—using infrared optical sensors and closed-loop differential motor control.
Bill of Materials (Required Components)
Part 1: Mechanical Chassis & Hardware Assembly
Step 1: Acrylic Sheet (Chassis) Preparation
Mechanical BaseThe acrylic base acts as the structural frame supporting all electronics, batteries, and drive assemblies.
- Peel Protective Film: Carefully remove the brown paper or plastic protective masking from both sides of the acrylic chassis plate.
- Inspect Mounting Slots: Verify the pre-cut T-slots for the BO motor clamps and the front mounting holes for the caster wheel.
- Mount the Caster Wheel: Attach the metal/plastic omni-directional caster wheel at the front center underside using M3 screws and brass standoffs to maintain level ground clearance.
Step 2: Mounting BO Motors & Wheels
Traction DriveDifferential steering relies on two independently driven rear wheels powered by geared BO (Battery Operated) motors.
- Pre-Solder Motor Leads: Solder 15cm red and black wires onto the copper terminals of both BO motors before mounting. Add a drop of hot glue over the solder joints for strain relief.
- Secure Motor Clamps: Slide the acrylic T-clamps into the rear chassis slots and bolt both BO motors firmly in place. Ensure both shafts are aligned along the exact same axis.
- Press-Fit Wheels: Align the flat D-shaft of each BO motor with the wheel hub and press the rubber wheels firmly onto the shafts.
Step 3: Mounting Other Components (Arduino, Driver & Battery)
Layout & BalanceProper weight distribution prevents wheel slip and keeps the center of gravity balanced over the drive axle.
- Arduino Uno: Mount the Arduino board in the center of the top deck using M3 nylon standoffs or heavy-duty double-sided foam tape.
- L298N Motor Driver: Position the L298N module directly behind or beside the Arduino so motor wires reach the screw terminals cleanly without tension.
- Battery Pack & Power Switch: Secure the 2-cell 18650 battery holder near the rear axle for better wheel traction, and mount a power switch in an easily accessible spot.
Step 4: Installing & Aligning IR Sensors
Optical ArrayInfrared sensors detect track contrast by emitting IR light and measuring the reflected intensity via a photodiode.
- Downward Orientation: Mount the Left and Right IR sensor modules facing straight down at the front edge of the acrylic chassis.
- Track Width Spacing: Set the center-to-center spacing between the two sensors slightly wider than your black track line (approx.
2.8 cm to 3.2 cmfor a 2.5 cm tape line) so the line passes cleanly between them. - Ground Clearance: Maintain a vertical gap of
1.0 cm to 1.5 cmbetween the IR LEDs and the floor to prevent ambient light interference.
Part 2: Wiring Structure & Pinout Architecture
Keep the battery switch OFF while completing all interconnections. Ensure a shared common ground (GND) between the battery, L298N driver, and Arduino Uno.
| Subsystem | Source Module Pin | Destination Pin | Signal / Power Function |
|---|---|---|---|
| Left BO Motor | Motor Wire A & B | L298N OUT1 & OUT2 |
Left wheel drive polarity |
| Right BO Motor | Motor Wire A & B | L298N OUT3 & OUT4 |
Right wheel drive polarity |
| Motor Direction | L298N IN1, IN2, IN3, IN4 |
Arduino Digital 8, 9, 10, 11 |
H-Bridge forward/reverse logic |
| Motor Speed (PWM) | L298N ENA & ENB |
Arduino PWM D5 & D6 |
Remove jumpers; enables speed control |
| Left IR Sensor | VCC / GND / OUT |
Arduino 5V / GND / D2 |
Left line detection digital input |
| Right IR Sensor | VCC / GND / OUT |
Arduino 5V / GND / D3 |
Right line detection digital input |
| Main Power | Battery (+) & (–) | L298N 12V & GND |
7.4V–9V primary motor supply |
| Logic Power | L298N 5V & GND |
Arduino 5V & GND |
Regulated 5V board power + Common GND |
Part 3: Arduino Control Firmware
Upload the following C++ sketch using the Arduino IDE. Adjust motorSpeed between 90 and 160 depending on your battery charge and track curvature.
// iTechBuilders - Line Follower Robot (LFR) Firmware
#define LEFT_SENSOR 2
#define RIGHT_SENSOR 3
// L298N Motor Driver Pins
#define ENA 5
#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11
#define ENB 6
int motorSpeed = 130; // PWM Speed (0 - 255)
void setup() {
pinMode(LEFT_SENSOR, INPUT);
pinMode(RIGHT_SENSOR, INPUT);
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(ENB, OUTPUT);
}
void loop() {
int leftState = digitalRead(LEFT_SENSOR);
int rightState = digitalRead(RIGHT_SENSOR);
// 0 = White Surface (IR Reflected), 1 = Black Line (IR Absorbed)
if (leftState == 0 && rightState == 0) {
moveForward();
}
else if (leftState == 1 && rightState == 0) {
turnLeft();
}
else if (leftState == 0 && rightState == 1) {
turnRight();
}
else {
stopRobot();
}
}
void moveForward() {
analogWrite(ENA, motorSpeed);
analogWrite(ENB, motorSpeed);
digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW);
}
void turnLeft() {
analogWrite(ENA, motorSpeed);
analogWrite(ENB, motorSpeed);
digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW);
}
void turnRight() {
analogWrite(ENA, motorSpeed);
analogWrite(ENB, motorSpeed);
digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH);
}
void stopRobot() {
digitalWrite(IN1, LOW); digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); digitalWrite(IN4, LOW);
}
Part 4: Sensor Calibration & Track Testing
Step 5: Track Setup, Potentiometer Tuning & Live Run
Final Verification- Build Test Track: Lay down a 2.5 cm wide matte black electrical tape path on a white chart paper or bright floor with smooth curves (avoid sharp 90° corners for 2-sensor builds).
- Calibrate IR Threshold: Power on the robot and hold the sensors over the white background. Turn the blue onboard potentiometer on each IR sensor until its signal LED turns ON. Move the sensor over the black tape—the LED must turn OFF.
- Execute Test Run: Center the robot straddling the black line and flip the power switch ON. Observe corner tracking and fine-tune PWM speed if overshoot occurs.
🔧 Interactive LFR Testing & Troubleshooting Helper
Select an issue observed during your test run for an instant hardware or code fix:
Comments
0