Go Down

Topic: please help me...code for line maze solver robot... (Read 1 time) previous topic - next topic

lovenijai

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...

Erdin

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

lovenijai

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...

afremont

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().
Experience, it's what you get when you were expecting something else.

lovenijai

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....

BillHo

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

lovenijai

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

AWOL

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
"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.

BillHo

Look, this is in your code, I think this is your problem of not able to taking turns properly.
Code: [Select]
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); 

}

Go Up