Pages: [1]   Go Down
Author Topic: please help me...code for line maze solver robot...  (Read 1451 times)
0 Members and 1 Guest are viewing this topic.
mumbai
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using arduino duemilanove atmega328 with 5 IR sensors and L293D to drive 2 DC motors....
I am posting my code below ....
Please help me to correct my code, its not working...

* LINEMAZE.txt (10.62 KB - downloaded 83 times.)
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is not working ?
Do the motors run ?
Do the detectors work ?
Logged

mumbai
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Motors are running perfectly...
Detectors are also working...
There is a problem in the condition given to sensors...It is not taking turns properly...I am not understanding what to do next...
Logged

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perhaps if you went thru the program and added some comments to describe what is supposed to be happening.  There are also recursive calls that don't look right to me in endmotion() and replay().
Logged

Experience, it's what you get when you were expecting something else.

mumbai
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The function endmotion() is to stop the robot after the second phase has been completed using shortest path...
And replay() is to traverse the robot through the shortest path in second phase....

My problem is that the robot is not taking the correct turns....
plz help....
Logged

SG
Offline Offline
God Member
*****
Karma: 11
Posts: 500
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is this (!digitalRead(leftNearReading)) do? the leftNearReading is 0 to 1023.
What you want the digitalRead() to read?
Logged

mumbai
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

digitalread is for digital signal of sensors high or low ...
 !(digitalread(leftfarsensor) means the leftfarsensor is low i.e on black line ..
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25898
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
!(digitalread(leftfarsensor) means the leftfarsensor is low i.e on black line ..
Suggest you read again what BillHo wrote, and look carefully at lines 56 and 77 of your code.
Hint: the Arduino doesn't have that many pins
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

SG
Offline Offline
God Member
*****
Karma: 11
Posts: 500
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look, this is in your code, I think this is your problem of not able to taking turns properly.
Code:
void loop()
{
readSensors();
if(leftFarReading>200 && (leftNearReading<200 || rightCenterReading<200 || rightNearReading<200) && rightNearReading>200)
{
if ((!digitalRead(leftNearReading)) && (!digitalRead(rightCenterReading)) && (!digitalRead(rightNearReading)))       // if all black
         {  MotorControl(1,1); Serial.println("forward");   }
        else if ((digitalRead(leftNearReading)) && (!digitalRead(rightCenterReading)) && (!digitalRead(rightNearReading)))    // if left on white // S3 out
         {  MotorControl(1,0); Serial.println("right"); }
        else if ((digitalRead(leftNearReading)) && (digitalRead(rightCenterReading)) && (!digitalRead(rightNearReading)))    // if left & middle on white // S3 & s2 out
         {  MotorControl(1,0); Serial.println("right sharp"); }
        else if ((!digitalRead(leftNearReading)) && (!digitalRead(rightCenterReading)) && (digitalRead(rightNearReading)))    // if right on white // s1 out
         {  MotorControl(0,1); Serial.println("left"); }
        else if ((!digitalRead(leftNearReading)) && (digitalRead(rightCenterReading)) && (digitalRead(rightNearReading)))    // if right & middle on white // S2 & s1 out
         {  MotorControl(0,1); Serial.println("left sharp"); }
}
else
{
leftHandWall();
}
}


void readSensors()
{
 
  leftNearReading    = analogRead(leftNearSensor);
  leftFarReading     = analogRead(leftFarSensor);
  rightCenterReading = analogRead(rightCenterSensor);
  rightNearReading   = analogRead(rightNearSensor);
  rightFarReading    = analogRead(rightFarSensor); 

}
Logged

Pages: [1]   Go Up
Jump to: