Day 01

Begineer

Day 26 :- Line Follower Robot

Sept 10, 2026

Completed

Wiring Schematic

Arduino Code

ARDUINO / C++

Day 26 Core Training Documentation

Project Overview

The Line Follower Robot project teaches you how to build an autonomous robot that follows a path by detecting and tracking a black line on the ground independently. This project combines infrared sensing with proportional motor control.

In this project, two infrared sensors detect the black line. Arduino reads the sensor values and adjusts motor speeds to keep the robot centered on the line. When the robot drifts left, the right motor speeds up. When it drifts right, the left motor speeds up.

When the robot powers up, it searches for the black line. Once detected, the robot automatically follows the line at consistent speed. The robot continuously corrects its position to stay centered on the line, navigating complex paths.

This project teaches Infrared Sensor Operation, Line Detection Algorithms, Proportional Control Systems, Motor Coordination, and Autonomous Path Following.

By finishing this project, you’ll know how line following robots work in manufacturing automation, warehouse sorting systems, and robotic delivery vehicles.

Components Required

To build this circuit, collect these specific items from your kit:

Arduino Uno × 1, Breadboard × 1, Robot Chassis × 1, DC Motors × 2, Motor Driver Module (L298N) × 1, Infrared Line Sensors × 2, Battery Pack (6V-9V) × 1, Caster Wheel × 1, Jumper Wires × 15, USB Cable × 1

Circuit Connections

Step 1: Connect Ground Rail

Connect the Arduino GND pin to the negative rail of the breadboard. This creates a shared ground connection for all robot components and power distribution system.

Step 2: Connect Battery to Motor Driver

Connect the positive terminal of the battery pack to the +12V input of the L298N motor driver. Connect the negative terminal to the GND of the motor driver for stable operation.

Step 3: Connect Motor Driver Outputs

Connect the left motor’s positive terminal to OUT1 of the motor driver and negative to OUT2. Connect the right motor’s positive terminal to OUT3 and negative to OUT4.

Step 4: Connect Motor Control Pins

Connect the ENA pin to Arduino Pin 5 and ENB pin to Arduino Pin 6 for PWM speed control. Connect IN1 to Pin 2, IN2 to Pin 3, IN3 to Pin 4 for direction control.

Step 5: Connect Left Infrared Sensor

Connect the left IR sensor VCC to Arduino 5V and GND to breadboard GND. Connect the output to Arduino Pin A0 for line detection on the left side.

Step 6: Connect Right Infrared Sensor

Connect the right IR sensor VCC to Arduino 5V and GND to breadboard GND. Connect the output to Arduino Pin A1 for line detection on the right side.

Step 7: Mount Sensors and Motors

Position the left IR sensor on the left side of the robot front. Position the right IR sensor on the right side approximately five centimeters apart. Secure motors to chassis.

Step 8: Verify Connections

Test motor rotation by manually turning the wheel. Verify IR sensor readings change when exposed to light and darkness. Check that sensors respond to the black line properly.

Important: Infrared sensors work best on high-contrast surfaces. A white floor with a black line provides optimal detection. Test the robot on the actual surface it will navigate.

How the Arduino Code Works

Initialize Sensors and Motors

In setup(), Arduino configures pins 2 through 6 as outputs for motor control. Pins A0 and A1 are configured as analog inputs for the infrared sensors. Serial Monitor starts at 9600 baud.

Read Infrared Sensor Values

Inside the main loop, Arduino reads both IR sensors using analogRead(). Sensor values range from 0 to 1023, where low values indicate the black line and high values indicate the white surface.

Determine Robot Position Relative to Line

The program compares the sensor readings to determine if the robot is centered on the line, drifting left, or drifting right. If both sensors read similar low values, the robot is centered.

Calculate Motor Speed Adjustment

Based on the sensor readings, the program calculates different motor speeds. If drifting left, the right motor speeds up to push the robot right. If drifting right, the left motor speeds up.

Continuous Correction Loop

The process repeats many times per second inside the loop() function. This rapid feedback allows the robot to make continuous small corrections, keeping it centered on the line perfectly.

Expected Output

After uploading your code, here is what happens.

After uploading your code, the robot moves forward and searches for the black line. When it detects the line, the robot follows it smoothly around corners and curves. The Serial Monitor displays left and right sensor readings continuously updating.

Operational Troubleshooting

Robot Does Not Follow the Line :- Verify the IR sensors are properly mounted and facing downward. Check that sensor values change when exposed to light and darkness. Test sensors independently to confirm operation.

Robot Oscillates Side to Side :- Reduce the correction speed values in your code. The robot is over-correcting and swinging excessively. Gradually adjust motor speed differences until smooth tracking is achieved.

Robot Moves Too Slowly :- Increase the base motor speed values in your code. Ensure the battery has sufficient charge to power the motors at higher speeds. Check for mechanical friction in wheels.

One Motor Does Not Respond to Speed Commands :- Verify the motor is properly connected to the driver output terminals. Check that the PWM pin connects to the correct Arduino pin. Test the motor independently.

IR Sensors Give Inconsistent Readings :- Clean the sensor lenses to remove dust and debris. Adjust the sensor mounting angle to ensure it faces directly downward. Check the lighting conditions on the surface.

What You Learned

By finishing this project, you now know :-

How infrared sensors detect contrasting surfaces accurately for navigation. You understand how proportional control systems create smooth automated responses. You learned to coordinate dual motors for precision movement control. You mastered line following algorithms for autonomous path tracking. You developed skills for building autonomous path-following robots.

Next Lesson

In Day 27, you’ll learn how to build a Weather Station that measures temperature, humidity, and displays all data in real-time on an OLED display. You will integrate multiple sensors and displays into one system.