Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: macbook on January 09, 2010, 05:23:08 AM

Title: Line follower using Arduino (Urgent!!!)
Post by: macbook on January 09, 2010, 05:23:08 AM
Hey,
I am wrking on a grid solving line follower bot using Arduino(ATmega 328). For line following i am using a 7 sensors sensor array (am using 4 out of 7 sensors). The problem is.... it isnt following what i am specifying in the code.. its taking turns on intersections on its own. I hav tested the sensors, they are wrking fine and sending proper signals to microcontroller. So I guess the prob is with my code.
I am pasting my code here.. kindly check and tell me where i went wrong..

int rtin = 3;  //inner right sensor //pin
int rtout = 2;  //outer right sensor
int ltin = 6;  //inner left sensor
int ltout = 7;  //outer left sensor //pin



void loop()
{
  if(digitalRead(ltin) == HIGH && digitalRead(rtin) == LOW && digitalRead(rtout) == LOW && digitalRead(ltout) == LOW)
  {
    do
    {
       right();
    }while(digitalRead(ltin) == HIGH);
    forward();
  }

  else if(digitalRead(rtin) == HIGH && digitalRead(ltin) == LOW && digitalRead(rtout) == LOW && digitalRead(ltout) == LOW)
  {
    do
    {
      left();
    }while(digitalRead(rtin) == HIGH);
    forward();
  }

  else if(digitalRead(rtin) == HIGH && digitalRead(rtout) == HIGH && digitalRead(ltin) == HIGH && digitalRead(ltout) == HIGH)
  {
    left();
    delay(2000);
   // forward();
  }

  else if(digitalRead(rtin) == HIGH && digitalRead(rtout) == LOW && digitalRead(ltin) == HIGH && digitalRead(ltout) == LOW)
  {
    forward();
  }
}


This code was written to test its line following... I wanted it to adjust itself on the line (first if and else if), turn left on the next intersection (2nd else if) and move forward otherwise.
I tested the forward, left, right commands individually and they are wrking fine.
The prob is instead of following the above commands, the bot is turning left and right alternatively at each junction (moving diagonally across the grid).

Please tell me if there is some problem with my code... or any other thing i should debug.. Tell me if u want some more info.
But i need the answer really soon.. I gotta complete this project by next week..
Thank you.
Title: Re: Line follower using Arduino (Urgent!!!)
Post by: Pratheek on January 09, 2010, 07:46:23 AM
Can you please give us more details like what do you want your robot to do? Where do you start in the grid and what is the target you want to reach?
Title: Re: Line follower using Arduino (Urgent!!!)
Post by: Soeren on January 09, 2010, 08:37:36 AM
Hi,

The problem is.... it isnt following what i am specifying in the code..
Another problem... This ought to go into the Software forum.