please help me...code for line maze solver robot...

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.6 KB)

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

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

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

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

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

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

!(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

Look, this is in your code, I think this is your problem of not able to taking turns properly.

void loop()
	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"); }

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