Third-Party Tutorials – Arduino Line Follower Robot

Third-Party Tutorials – Arduino Line Follower Robot

In this tutorial you will learn how to make an Arduino line follower robot!

It’s a very cool project and it’s one of the first important project that a maker has to make!!!

You will learn how followng this guide!

What is a Line Follower Robot?

A line follower is a robot that thanks to its sensors can follow a line. Usually it’s a black line, and it uses IR sensors (we already did a tutrial for this sensor! check it out here!!).

What’s the concept behind a Line Folower Robot?

Concept of working of line follower is related to light. Infact we use the IR sensor. You have to know that a white surface reflets the light and the black surface absorbe it. This behavior of light is used in building a line follower robot.

Light absorbed
light reflected

How it works?

In this project we are using two IR sensor modules (left and right). When both left and right sensor senses white, the robot moves forward.

If the left sensor comes on black line, the robot turns left side.

If the right sensor comes on black line, the robot turns right side.

When white surface comes robot starts moving on forward again.

If both sensors comes on black line, robot stops.


Sketch

  int vSpeed = 110;        // MAX 255
  int turn_speed = 230;    // MAX 255 
  int turn_delay = 10;
  
//L293 Connection   
  const int motorA1      = 8;  
  const int motorA2      = 10; 
  const int motorAspeed  = 9;
  const int motorB1      = 12; 
  const int motorB2      = 13; 
  const int motorBspeed  = 11;

//Sensor Connection
  const int left_sensor_pin =A0;
  const int right_sensor_pin =A1;

  
  
  int left_sensor_state;
  int right_sensor_state;

void setup() {
  pinMode(motorA1, OUTPUT);
  pinMode(motorA2, OUTPUT);
  pinMode(motorB1, OUTPUT);
  pinMode(motorB2, OUTPUT);

  Serial.begin(9600);

  delay(3000);
  
}

void loop()
{
left_sensor_state = analogRead(left_sensor_pin);
right_sensor_state = analogRead(right_sensor_pin);

if(right_sensor_state > 500 && left_sensor_state < 500)
{
  Serial.println("turning right");

  digitalWrite (motorA1,LOW);
  digitalWrite(motorA2,HIGH);                       
  digitalWrite (motorB1,LOW);
  digitalWrite(motorB2,HIGH);

  analogWrite (motorAspeed, vSpeed);
  analogWrite (motorBspeed, turn_speed);
  
  }
if(right_sensor_state < 500 && left_sensor_state > 500)
{
  Serial.println("turning left");
  
  digitalWrite (motorA1,HIGH);
  digitalWrite(motorA2,LOW);                       
  digitalWrite (motorB1,HIGH);
  digitalWrite(motorB2,LOW);

  analogWrite (motorAspeed, turn_speed);
  analogWrite (motorBspeed, vSpeed);

  delay(turn_delay);
  }

if(right_sensor_state > 500 && left_sensor_state > 500)
{
  Serial.println("going forward");

  digitalWrite (motorA2,LOW);
  digitalWrite(motorA1,HIGH);                       
  digitalWrite (motorB2,HIGH);
  digitalWrite(motorB1,LOW);

  analogWrite (motorAspeed, vSpeed);
  analogWrite (motorBspeed, vSpeed);

  delay(turn_delay);
  
  }

if(right_sensor_state < 500 && left_sensor_state < 500)
{ 
  Serial.println("stop");
  
  analogWrite (motorAspeed, 0);
  analogWrite (motorBspeed, 0);
  
 }
}

Credits for this Arduino line follower robot

I took Arduino Line Follower Robot project from Arduino project hub, infact I put it in the Third-Party project section.

I know that there aren’t schematics, I will make a my own line follower and I wll ost schematics for everything! No you can use the schematics from this 2 tutorials

  1. IR Sensor
  2. Motors

Davide Busco

Davide Busco is an engineering student at Federico II University of Naples. He uses his passion and studies to create his projects. He loves be a maker and spread his knowledge. Moreover he has gained the second place in a national makers-tournament between Italian's Universities.

Leave a Reply

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

en_GBEnglish (UK)
it_ITItaliano en_GBEnglish (UK)
%d bloggers like this: