Searching...

search_off

No products found

folder Project Ideas
• • 1 min read • visibility 324 views

How to Build a Line Following Robot with Arduino — Complete Guide

A
Admin User
Technical Specialists & Component Engineers
Share: chat share
How to Build a Line Following Robot with Arduino — Complete Guide
Build your first autonomous robot! This complete guide covers the chassis, IR sensors, motor driver, and Arduino code to make a robot that follows a black line on white surface.

Components Required

  • Arduino Uno R3
  • 2x BO Motor (300 RPM)
  • L298N Motor Driver Module
  • 2x IR Sensor Module
  • Robot Chassis with wheels
  • 9V or 12V Battery with holder
  • Jumper wires

How Line Following Works

IR sensors emit infrared light. When over a white surface, light reflects back (HIGH). Over a black line, light is absorbed (LOW). Two sensors placed side by side detect the line position and steer the robot accordingly.

Wiring

Connect both IR sensors to Arduino digital pins D2 and D3. Connect L298N motor driver: IN1→D5, IN2→D6, IN3→D9, IN4→D10, ENA→D3 (PWM), ENB→D11 (PWM). Connect 12V battery to L298N power input. 5V from L298N powers Arduino.

Arduino Code

int leftSensor = 2, rightSensor = 3;
void setup() { pinMode(leftSensor, INPUT); pinMode(rightSensor, INPUT); }
void loop() {
  bool L = digitalRead(leftSensor);
  bool R = digitalRead(rightSensor);
  if (!L && !R) forward();
  else if (L && !R) turnLeft();
  else if (!L && R) turnRight();
  else stop();
}

Testing & Tuning

Place the robot on a white sheet with a 2cm wide black line. Adjust the IR sensor sensitivity screws for reliable detection. Fine-tune motor speeds in the forward/turn functions.

All components available at Anilestore — complete robotics kits also available for convenience!

Found this helpful? Share with fellow engineers, makers, and students.
AE
Written by Store Specialists

Anil Electronic Store Technical Team

Based in Odhav, Ahmedabad, we provide genuine electronic components, Arduino boards, robotics hardware, and industrial automation parts across India.

home Home grid_view Catalog
shopping_cart
Cart
person Login