Line Tracer using Arduino UNO - Tutorial with video explanation and Code

Introduction:

Line tracer robot is nothing but a motor driven car which follows the black line with the help of IR sensor module, motors and of course the heart of this bot Arduino UNO (ATMEGA328P).

Parts Needed:

1)Arduino UNO (ATMEGA328P)












2)2 DC motors 












3)L293D Circuit to drive the DC motors











4)IR Sensor Module to sense the black line minimum of 3












5)12v Battery for 2 motors












6)9v Battery for Aduino board












7)2 number of Wheels












8)1 Caster Wheel for balancing












Connections:

Make the connections as shown in the above figure. Here set the input pins A1,A2,A3 to receive signal from the IR sensors. Connect the motor driving circuit L293D from 3,5 and 9,10 in arduino board which was set as output. From L293D connect the 2 motors. Then connect the appropriate supply and grounds. Complete the connection setup with the help of acryllic chasers. Thats it your line tracer bot's setup is ready.

Program:

Basic Line follower:

int left=A0, middle=A1, right=A2;
int lm=9, rm=11, lmr=5, rmr=10;
int s=55;
void setup()
{
  pinMode(5,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
 }
void loop()
{
  analogWrite(lm,s);
  analogWrite(rm,s);
  analogWrite(lmr,0);
  analogWrite(rmr,0);
  while((analogRead(left)>45)&&(analogRead(middle)<45)&&(analogRead(right)>45));
  if((analogRead(left)<45))
  {
    analogWrite(lm,0);
  }
  if((analogRead(right)<45))
  {
    analogWrite(rm,0);
  }
  while(((analogRead(left)<45)||(analogRead(right)<45))&&(analogRead(middle)>45));
  delay(100);
}

With 4 sensors and high speed:

Some more logic is added in program which is capable of passing many loops in the track. 


int left=A0, middle=A1, right=A2;

int lm=9, rm=11, lmr=5, rmr=10;

int s=110, t=45, flg=0;

void rt()

{

  analogWrite(lm,s);

  analogWrite(rm,0);

  while(analogRead(A1)>t);

  delay(30);

}

void lt()

{
  analogWrite(lm,0);
  analogWrite(rm,s);
  while(analogRead(A1)>t);
  delay(30);
}

void setup()
{
  pinMode(5,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  analogWrite(lm,s);
  analogWrite(rm,s);
  analogWrite(lmr,0);
  analogWrite(rmr,0);
}
void loop()
{
  analogWrite(lm,s);
  analogWrite(rm,s);
  if(analogRead(A3)>t)
  {
    if(flg==0)
    {
      flg=1;
    }
  }
  if(analogRead(A1)<t)
  {
    if((analogRead(A2)<t)&&(analogRead(A0)<t))
    {
      if(analogRead(A3)<t)
      {
        if(flg)
        {
          analogWrite(lm,0);
          analogWrite(rm,0);
          while(analogRead(A3)<t);
        }
      }
      else
      {
      }
    }
    else if(analogRead(A2)<t)
    {
      while(analogRead(A2)<t);
    }
    else if(analogRead(A0)<t)
    {
      while(analogRead(A0)<t);
    }
  }
  else
  {
    if((analogRead(A0)<t)&&(analogRead(A2)<t))
    {
      rt();
    }
    else if(analogRead(A0)<t)
    {
      lt();
    }
    else if(analogRead(A2)<t)
    {
      rt();
    }
  }
}

Download these program to the arduino board using the arduino ide. Then Power the bot ON by giving supply for both motor and arduino. Thats it Your Line tracer Robot is ready.

Video:



Drop your doubts in the comments.

Cheers!!!!
-> Let Us Embed <-