Complete Project Intermediate 25 دقيقة

Arduino Line Follower Robot: Step-by-Step Build Guide, Circuit & Code

Build an autonomous line follower robot using Arduino Uno, TCRT5000 IR reflectance sensors, L9110S motor driver, and 18650 battery pack.

Verified by MOKWN Hardware Engineering Team
Arduino Line Follower Robot: Step-by-Step Build Guide, Circuit & Code
Required Components (BOM)

Project Components Available in Egypt

All components tested and genuine with fast nationwide delivery in Egypt

Add All to Cart
2WD Smart Robot Car Chassis
Qty: 1
2WD Smart Robot Car Chassis
شاسيه روبوت متين بموتورين وعجلتين وعجلة كاستور حرة
Arduino UNO R3 SMD Development Board with cable
Qty: 1
Arduino UNO R3 SMD Development Board with cable
العقل المدبر لمعالجة إشارات الحساسات وتوجيه المحركات
Line Tracker (Finder) Sensor
Qty: 2
Line Tracker (Finder) Sensor
حساسين أشعة تحت حمراء للتمييز الفوري بين الخط الأسود والأرضية البيضاء
L9110S Dual DC & Stepper Motor Driver Module (H-Bridge)
Qty: 1
L9110S Dual DC & Stepper Motor Driver Module (H-Bridge)
درايفر مواتير H-Bridge مدمج وفعال للتحكم في اتجاه وسرعة الموتورين
18650 Lithium-Ion Rechargeable Battery 3500mAh 3.7V
Qty: 2
18650 Lithium-Ion Rechargeable Battery 3500mAh 3.7V
بطاريتان ليثيوم لتوفير جهد 7.4V كافي للمواتير دون انخفاض الفولت

Introduction: The Foundational Robotics Milestone

The autonomous line follower robot is the quintessential project bridging embedded C++ firmware, analog sensor acquisition, and electro-mechanical motor control.

Equipped with dual TCRT5000 infrared reflectance sensors and an H-bridge driver, the robot tracks high-contrast electrical tape lines in real time.

---

Operating Principle

  • White Surface: High infrared reflectance triggers the phototransistor, outputting logic LOW (0).
  • Black Line: Absorbs infrared radiation; no signal reflects back, outputting logic HIGH (1).

---

Complete Wiring Layout

  • Left IR Sensor Output: Pin 2
  • Right IR Sensor Output: Pin 3
  • Motor Driver Left Forward (PWM): Pin 5
  • Motor Driver Left Reverse: Pin 6
  • Motor Driver Right Forward (PWM): Pin 9
  • Motor Driver Right Reverse: Pin 10
  • Driver Power (VCC): 7.4V (2x 18650 in series)
  • Common Ground: Connect battery negative, motor driver GND, and Arduino GND together.

---

Arduino C++ Source Code

const int leftSensorPin = 2;
const int rightSensorPin = 3;

const int motorLeftFwd = 5;
const int motorLeftRev = 6;
const int motorRightFwd = 9;
const int motorRightRev = 10;

const int forwardSpeed = 160;
const int turnSpeed = 180;

void setup() {
  pinMode(leftSensorPin, INPUT);
  pinMode(rightSensorPin, INPUT);
  pinMode(motorLeftFwd, OUTPUT);
  pinMode(motorLeftRev, OUTPUT);
  pinMode(motorRightFwd, OUTPUT);
  pinMode(motorRightRev, OUTPUT);
  stopMotors();
  delay(1000);
}

void loop() {
  int left = digitalRead(leftSensorPin);
  int right = digitalRead(rightSensorPin);

  if (left == LOW && right == LOW) {
    moveForward();
  } else if (left == HIGH && right == LOW) {
    turnLeft();
  } else if (left == LOW && right == HIGH) {
    turnRight();
  } else {
    stopMotors();
  }
}

void moveForward() {
  analogWrite(motorLeftFwd, forwardSpeed);
  digitalWrite(motorLeftRev, LOW);
  analogWrite(motorRightFwd, forwardSpeed);
  digitalWrite(motorRightRev, LOW);
}

void turnLeft() {
  digitalWrite(motorLeftFwd, LOW);
  digitalWrite(motorLeftRev, LOW);
  analogWrite(motorRightFwd, turnSpeed);
  digitalWrite(motorRightRev, LOW);
}

void turnRight() {
  analogWrite(motorLeftFwd, turnSpeed);
  digitalWrite(motorLeftRev, LOW);
  digitalWrite(motorRightFwd, LOW);
  digitalWrite(motorRightRev, LOW);
}

void stopMotors() {
  digitalWrite(motorLeftFwd, LOW);
  digitalWrite(motorLeftRev, LOW);
  digitalWrite(motorRightFwd, LOW);
  digitalWrite(motorRightRev, LOW);
}

---

Pro Troubleshooting Tips

  1. Reversed Steering: Swap the two motor lead wires on the terminal block to reverse rotation direction.
  2. Sensor Standoff Distance: Mount sensor heads strictly between 4mm and 7mm above the surface for optimal focal reception.
  3. Common Ground: Ensure the 18650 battery pack negative and the Arduino GND pin are firmly bridged together.

Frequently Asked Questions

Why does the Arduino reset itself as soon as the motors start moving?

Inrush motor current causes sudden voltage drops (brownouts) that trigger an MCU reset. Fix this by using quality high-drain 18650 cells and never powering DC motors directly from Arduino 5V pins.

How do I calibrate TCRT5000 line tracker sensor sensitivity?

Use the onboard blue trim potentiometer. Place the sensor over the white floor and turn until the indicator LED activates, then slide over the black tape to verify the LED turns off completely.

Can the robot work reliably with only 2 sensors?

Yes, two sensors work great for smooth tracks using simple 2-state steering logic. For 90-degree sharp corners, intersections, or racing competitions, a 3-sensor or 5-sensor array with PID control is recommended.

Ask Volt AI Hardware Assistant

Need help debugging your circuit wiring or verifying your code? Chat with Volt directly.

Start Chat with Volt