Project tutorial
Line Follower Robot

Line Follower Robot

Full procedure with theory explaining the concept behind a line follower robot

  • 748 views
  • 0 comments
  • 3 respects

Components and supplies

Necessary tools and machines

Apps and online services

About this project

Line Follower Robot

Understanding the circuit and its components:

Component 1: The IR Proximity Sensors

The concept of working of a line follower robot is based on the phenomenon of light. We know that white colour reflects almost all of the light that falls on it, whereas black colour absorbs most of the light. In case of a line follower robot we use IR transmitters and receivers also called photodiodes. They are used for sending and receiving light. IR transmits infrared lights. When infrared rays falls on white surface, it’s reflected back and catched by photodiodes which generates some voltage changes. When IR light falls on a black surface, light is absorb by the black surface and no rays are reflected back, thus photo diode does not receive any light or rays.

Here in this Arduino line follower robot when sensor senses white surface then Arduino gets 1, ie, HIGH as input and when senses black line arduino gets 0, ie, LOW as input.

Circuit connections for IR Proximity Sensors:

  • The IR sensor is a 3 three wired sensor, in which the brown and the black wire are used to connect the sensor to the power supply, whereas, the red wire is connected to the load, or Arduino, in our circuit.
  • The load wires of the IR sensors are connected to pin 8, 9 and 10 as shown in the schematic.

Component 2 : L298N H-Bridge Motor Driver

The H-Bridge Motor Drivers L298N is used to drive DC motors as they require much more current that the arduino can provide.

The L298N motor controller follows the H-bridge configuration, which is handy when controlling the direction of rotation of a DC motor. The other benefit of using an H-bridge is that we can provide a separate power supply to the motors. This is very significant especially when using an Arduino board where the 5V power source is simply not enough for two DC motors.

We have Motor A and Motor B terminals. These connect to the microcontroller. Motor A connects to terminals 1 and 2 while Motor B connects to terminals 3 and 4.

If we want the left motor to rotate in one direction, we apply a high pulse to IN1 and a low pulse to IN2. To reverse the direction, reverse the pulses to IN1 and IN2. The same applies to the right motor.

If we want the left motor to rotate in one direction, we apply a high pulse to IN1 and a low pulse to IN2. To reverse the direction, reverse the pulses to IN1 and IN2. The same applies to the right motor.

Speed control is also possible with the L298N motor driver. All we need is feed PWM ( Pulse Width Modulation) signals to the motor enable pins. The speed of the motor will vary according to the width of the pulses. The wider the pulses, the faster the motor rotates. In Arduino this can be done using analogWrite(pinNumber, duration). Pins on Arduino with β€˜~’ support PWM.

Circuit connections forL298N H-Bridge Motor Driver :

  • Motor A wires are connected to motor terminal 1 and 2 of L298N, whereas Motor B wires are connected to motor terminal 3 and 4. IN1, IN2, IN3 and IN4 are connected to pin 2, 3, 4, 7 respectively.
  • Now, Motor A and Motor B Enable should be connected to terminals on arduino which have ~ sign, so that speed of these motors can be controlled using PWM. Here, they have been connected to pin 5 and 6.
  • Other connections are clear from the schematic.

Procedure:

Step 1: Connect the circuit as shown in the schematic.

Step 2: Use the Arduino IDE to write your own code.

Step 3: Upload your code to the Arduino and connect it to the batteries or you can even use a power bank to run the Arduino.

Step 4: Test it on a black path.

Code

Line_Follower.inoArduino
// Black Line Follower 
int IR1=8;      //Right sensor
int IR2=9;    //left Sensor
// motor one
int enA = 5;    //Right motor
int MotorAip1=2;
int MotorAip2=3;
// motor two
int enB = 6;    //Left motor
int MotorBip1=4;
int MotorBip2=7;
void setup() 
{
  // put your setup code here, to run once:
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(IR1,INPUT);
  pinMode(IR2,INPUT);
  pinMode(MotorAip1,OUTPUT);
  pinMode(MotorAip2,OUTPUT);
  pinMode(MotorBip1,OUTPUT);
  pinMode(MotorBip2,OUTPUT);
}
void loop() 
{
   if(digitalRead(IR1)==HIGH && digitalRead(IR2)==HIGH) //IR will not glow on black line
  {
    //Stop both Motors
    digitalWrite(MotorAip1,LOW);
    digitalWrite(MotorAip2,LOW);
    digitalWrite(MotorBip1,LOW);
    digitalWrite(MotorBip2,LOW);
   analogWrite (enA, 0);
   analogWrite (enB, 0);
  }

  else if(digitalRead(IR1)==LOW && digitalRead(IR2)==LOW)  //IR not on black line
  {
    //Move both the Motors
    digitalWrite(MotorAip1,HIGH);
    digitalWrite(MotorAip2,LOW);
    digitalWrite(MotorBip1,HIGH);
    digitalWrite(MotorBip2,LOW);
    analogWrite (enA, 200);
    analogWrite (enB, 200);
  }

  else if(digitalRead(IR1)==LOW && digitalRead(IR2)==HIGH)
  {
    //Tilt robot towards left by stopping the left wheel and moving the right one
    digitalWrite(MotorAip1,HIGH);     
    digitalWrite(MotorAip2,LOW);
    digitalWrite(MotorBip1,LOW);
    digitalWrite(MotorBip2,HIGH);
    analogWrite (enA, 200);
    analogWrite (enB, 150);
   delay(100);
  }

  else if(digitalRead(IR1)==HIGH && digitalRead(IR2)==LOW)
  {
    //Tilt robot towards right by stopping the right wheel and moving the left one
     digitalWrite(MotorAip1,LOW);     // If I want to turn right then the speed of the right wheel should be less than that of the left wheel, here, let a be the right wheel
    digitalWrite(MotorAip2,HIGH);
    digitalWrite(MotorBip1,HIGH);
    digitalWrite(MotorBip2,LOW);
    analogWrite (enA, 150);
   analogWrite (enB, 200);
   delay(100);
  }

  else
  {
    //Stop both the motors
    digitalWrite(MotorAip1,LOW);
    digitalWrite(MotorAip2,LOW);
    digitalWrite(MotorBip1,LOW);
    digitalWrite(MotorBip2,LOW);
    analogWrite (enA, 0);
   analogWrite (enB, 0);
  }
}

Schematics

Circuit
Screenshot 2020 08 23 at 11 56 42 am n63giekksa

Comments

Similar projects you might like

Line Follower Robot

Project tutorial by Shubham Shinganapure

  • 12,924 views
  • 3 comments
  • 26 respects

Easiest Line Follower Robot

Project tutorial by Zubayer Al Billal Khan

  • 37,012 views
  • 14 comments
  • 58 respects

Amazing 6WD Off-Road Robot | Arduino RC Robot

Project tutorial by Jithin Sanal

  • 14,901 views
  • 1 comment
  • 71 respects

Simple Line Follower Robot

Project tutorial by Harsh Dethe

  • 5,928 views
  • 0 comments
  • 10 respects

PID Control Line Follower Robot

Project tutorial by Team KittenBot

  • 34,449 views
  • 6 comments
  • 39 respects

How to Make a Gesture Control Robot at Home

Project tutorial by Shubham Shinganapure

  • 16,645 views
  • 20 comments
  • 75 respects
Add projectSign up / Login