Author Topic: Line follower using Arduino (Urgent!!!)  (Read 6643 times)

0 Members and 2 Guests are viewing this topic.

Offline macbookTopic starter

  • Jr. Member
  • **
  • Posts: 45
  • Helpful? 0
Line follower using Arduino (Urgent!!!)
« 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.

Offline Pratheek

  • Contest Winner
  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 3
Re: Line follower using Arduino (Urgent!!!)
« Reply #1 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?

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Line follower using Arduino (Urgent!!!)
« Reply #2 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.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

 


Get Your Ad Here

data_list