How to make a Line follower robot using Arduino UNO board

How to make a Line follower robot using Arduino UNO board

   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 sensors that can receive signals using infrared rays. For that, include two IR infrared diodes 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 detection technology. Do you want more information about these sensors? Please visit my previous IR Sensor tutorial. For that, click on this link. Today I am using the following IR sensor for making the robot.

How to make a Line follower robot using Arduino UNO board

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, 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.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Okay, let’s identify these components first.

Step 2

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

How to make a Line follower robot using Arduino UNO board

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 method. 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.

How to make a Line follower robot using Arduino UNO board

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.

How to make a Line follower robot using Arduino UNO board

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.

How to make a Line follower robot using Arduino UNO board

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);
  Serial.begin(9600);
}
 
void loop() {
  bool LValue = digitalRead(SL);//get sensor value one 
  bool RValue = digitalRead(SR);//get sensor value two 
 
  Serial.print(LValue);
  Serial.println(RValue);
 
  if (RValue == 1 && LValue == 0 ) {
    turnRight();
    Serial.println("turnRight");
  } else if (LValue == 1 && RValue == 0) {
    turnLeft();
    Serial.println("turnLeft");
  } else if (LValue == 0 && RValue == 0) {
    forward();
    Serial.println("forward");
  } else if (LValue == 1 && RValue == 1) {
    Stop();
    Serial.println("stop");
  }
 
 
}
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.

Step 11

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

Step 12

Finally, connect the power source and enjoy it.

OK, enjoy this project. The full video guide is below. So, we hope to see you in the next project.

How to make a Line follower robot using Arduino UNO board

Leave a Comment

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

Shopping Cart
Select your currency
EUR Euro
Scroll to Top