Need help regarding line follower bot

Hey guys i am making line follower bot using arduino uno r3 with three IR sensor module… and can anyone help me if my logic and code is right or not… and help me correcting it… Thanks in advanced.

line follower.ino (1.87 KB)

(deleted)

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

We also need to see how your hardware is connected.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :)

Maybe make the sensor first and just use your hands/a toy car to see if it outputs what you would expect before trying to put it all on a robot to end up taking it all apart again later.

Hi,
What colour line are you going to follow?


Tom... :slight_smile:

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

We also need to see how your hardware is connected.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks… Tom… :slight_smile:

Hii… Tom… thanks for the reply. The code is given below…

int mot1=9;
int mot2=6;
int mot3=5;
int mot4=3;

int left=13;
int mid=8;
int right=12;

int Left=0;
int Mid=0;
int Right=0;

void LEFT (void);
void RIGHT (void);
void STOP (void);

void setup()
{
  pinMode(mot1,OUTPUT);
  pinMode(mot2,OUTPUT);
  pinMode(mot3,OUTPUT);
  pinMode(mot4,OUTPUT);

  pinMode(left,INPUT);
  pinMode(mid,INPUT);
  pinMode(right,INPUT);

  digitalWrite(left,HIGH);
  digitalWrite(mid,LOW);
  digitalWrite(right,HIGH);
  
  
}

void loop() 
{
 
analogWrite(mot1,255);
analogWrite(mot2,0);
analogWrite(mot3,255);
analogWrite(mot4,0);

while(1)
{
  Left=digitalRead(left);
  Mid=digitalRead(mid);
  Right=digitalRead(right);
  
  if(((Left==0 && Mid==0 && Right==1) || (Left==1 && Mid==1 && Right==0))==1)
  LEFT();
  else if(((Right==0 && Mid==0 && Left==1) || (Right==1 && Mid==1 && Left==0))==1)
  RIGHT();
}
}

void LEFT (void)
{
   analogWrite(mot3,0);
   analogWrite(mot4,30);
   
   
   while(Left==0)
   {
    Left=digitalRead(left);
    Right=digitalRead(right);
    if(Right==0)
    {
      int lprev=Left;
      int rprev=Right;
      STOP();
      while(((lprev==Left)&&(rprev==Right))==1)
      {
         Left=digitalRead(left);
         Right=digitalRead(right);
      }
    }
    analogWrite(mot1,255);
    analogWrite(mot2,0); 
   }
   analogWrite(mot3,255);
   analogWrite(mot4,0);
}

void RIGHT (void)
{
   analogWrite(mot1,0);
   analogWrite(mot2,30);

   while(Right==0)
   {
    Left=digitalRead(left);
    Right=digitalRead(right);
    if(Left==0)
    {
      int lprev=Left;
      int rprev=Right;
     STOP();
      while(((lprev==Left)&&(rprev==Right))==1)
      {
         Left=digitalRead(left);
         Right=digitalRead(right);
      }
    }
    analogWrite(mot3,255);
    analogWrite(mot4,0);
    }
   analogWrite(mot1,255);
   analogWrite(mot2,0);
}
void STOP (void)
{
analogWrite(mot1,0);
analogWrite(mot2,0);
analogWrite(mot3,0);
analogWrite(mot4,0);
  
}

I have attached circuit diagram that i am gonna follow to make the bot.
But i have my doubts regarding the connection of middle IR module to pin 8. Anyway i am gonna try it and confirm it. And the path of bot is also attached with the post. At first it is black strip on white background and afterwards white on black.
Also i have not written the whole code… it is taken from the reference site… they used two ir modules for simpler path And here is the link of that site : https://www.electronicshub.org/arduino-line-follower-robot/

Thanks in advance! :slight_smile: :slight_smile:

Hi,
Thanks for the schematic.
515d3b8e6c0c0f907ad3c76b1c37f0d349d142cd.jpg
OPs Track
b29b6647b407dc15a82d0e9431a9e5876ad9d1a9.jpg

Looks like a good start, yes try what you have to get your directions and sensing circuit working.

Tom… :slight_smile: