Line follower robot

   Hello guys, welcome back. Today we will learn how to make a line follower robot. A line follower robot is a robot that can only move through lines. But, this robot cannot move through different color lines. Because the robot only moves on the black lines. Also, these black lines should be installed on a white surface. That’s when this robot moves correctly. This is because the robot can only recognize black and white.

So let’s find out how this robot works. For that, mainly uses IR infrared sensors.

What is an IR infrared sensor?

IR sensors are a sensor that can receive the signals using infrared rays. For that, includes two IR infrared diode in these sensors. One diode emits infrared rays and the other diode absorbs those rays. We can change the infrared rays’ reflectance distance using the potentiometer in these sensors. Also, we can change this distance range from 1mm to 25mm. So, we can get two benefits from these sensors. That is, identifying black and white and avoiding obstacles. Today we use only one benefit. That is black and white identification technology. Do you want more information about these sensors? Please visit my previous IR Sensor tutorial. For that, click on this linkToday I am using the following IR sensor for making the robot.
Okay, next we need two gear motors to move the robot. But we can’t control these motors directly through the Arduino board. For that, we need a motor driver board. For this project for I’m using the L298N motor driver board. It can control two motors. If you want more information on this motor driver board please click this link. Next, we need to control all components. For that, I use the Arduino UNO board. Because it is so easy to use. Okay, here is the complete list of components we need. You can buy components easily using these links.


OK, let’s do this project step by step. Please note that I use low-cost methods to build this robot.

Step 1

Okay, let’s identify these components first.
Arduino UNO board.
IR infrared sensor.

L298N Motor Driver Board.
Gear Motor.
Robot wheel
Jumper wires
Popsicle sticks
Phone battery

Step 2

Okay, now let’s start making the robot car chassis. First, attach the robotic wheel to the motor.

Step 3

Next, glue the two motors together using the popsicle sticks. For that, I’m using a glue gun and glue sticks. You can use any other methods. Look at the pictures below.

Step 4

Then, attach the other wheel to the robot chassis we made above. Use popsicle sticks for that.

Step 5

Next, connect the two IR sensors to one popsicle rod and then attach it to the main chassis.

Step 6

Okay, now the robot car chassis is complete. Next, attach the motor driver board and Arduino board to the robot car chassis.

Step 7

Then, connect all these components to the Arduino Uno board. For that, use the circuit diagram below.

Step 8

Next, attach the power source to the robot car. For that, I use two mobile phone batteries. You can use any other power source. But please keep in mind that its voltage range is 7.2 – 12VDC.

Step 9

Okay, now that work is done. Now, all we have to do is upload the program. For that, connect the Arduino board to the computer using a USB cable.

Step 10

OK, let’s look at the code below.
The complete program of this project – Download
/*Line following robot.
  created by SriTu Tech team.
  Read the code below and use it for any of your creation
//motor one
#define ENA 5
#define IN1 2
#define IN2 3
//motor two
#define ENB 6
#define IN3 7
#define IN4 8
//sensor pins
#define SL 10
#define SR 9
int mSpeed = 130;//motor speed
void setup() {
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(SL, INPUT);
  pinMode(SR, INPUT);
void loop() {
  bool LValue = digitalRead(SL);//get sensor value one 
  bool RValue = digitalRead(SR);//get sensor value two 
  if (RValue == 1 && LValue == 0 ) {
  } else if (LValue == 1 && RValue == 0) {
  } else if (LValue == 0 && RValue == 0) {
  } else if (LValue == 1 && RValue == 1) {
void turnRight() {
  analogWrite(ENA, mSpeed);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  analogWrite(ENB, 0);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
void turnLeft() {
  analogWrite(ENB, mSpeed);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  analogWrite(ENA, 0);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
void forward() {
  analogWrite(ENA, mSpeed);
  analogWrite(ENB, mSpeed);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
void Stop() {
  analogWrite(ENA, 0);
  analogWrite(ENB, 0);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
This code is very easy. First, the Arduino pins used are defined. Then, an integer variable is created to control the rotational speed of the motors. Next, in the void setup function, the Arduino pins we use are defined as inputs and outputs. Finally, the void loop function includes the robot car moving code. Please read and understand this code carefully.
The complete program of this project – Download

Step 11

Now select the correct Arduino board and port. Then upload this code to the line following robot.

Step 12

Finally, connect the power source and enjoy it.
Below is the full video guide of this post. I think this article is important to you. Ok, we will meet in the next post. Have a good day. Bye-bye.

Line follower robot

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
Scroll to Top