not working this program

the following program is for line follower.
there is no error message while compiling but this is not working for my robot.
does aurdino support do_while loop ?
what are the corrections i want to make in this program to run my robo smoothly.
my logic is, if a right turn is come, robo will take right turn until straight condition comes. other junctions are also like this.
please help.

void setup()
{
pinMode(10,OUTPUT);
pinMode(9,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);

pinMode(14,INPUT);
pinMode(15,INPUT);
pinMode(16,INPUT);
pinMode(17,INPUT);
pinMode(18,INPUT);

Serial.begin(9600);

}

void loop()
{
int S1=digitalRead(14);
int S2=digitalRead(15);
int S3=digitalRead(16);
int S4=digitalRead(17);
int S5=digitalRead(18);

if(S1==LOW && S2==LOW && S3==LOW && S4==LOW && S5==LOW) //0 0 1 0 0 NORMAL STRAIGHT
{
Serial.print("STRAIGHT");
digitalWrite(10,LOW); //STRAIGHT
digitalWrite(9,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
}
else if (S1==LOW && S2==HIGH && S3==LOW && S4==HIGH && S5==LOW) //0 1 1 1 0 + CROSS
{
do
{
Serial.print("+ CROSS");
digitalWrite(10,LOW); //LEFT
digitalWrite(9,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
}
while(!(S1==LOW && S2==LOW && S3==LOW && S4==LOW && S5==LOW));
}
else if (S1==LOW && S2==HIGH && S3==LOW && S4==LOW && S5==LOW) //0 1 1 0 0 LEFT JUNCTION
{
do
{
Serial.print("LEFT JUNCTION");
digitalWrite(10,LOW); //LEFT
digitalWrite(9,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
}
while(!(S1==LOW && S2==LOW && S3==LOW && S4==LOW && S5==LOW));
}
else if (S1==LOW && S2==LOW && S3==LOW && S4==HIGH && S5==LOW) //0 0 1 1 0 RIGHT JUNCTION
{
do
{
Serial.print("RIGHT JUNCTION");
digitalWrite(10,LOW); //STRAIGHT
digitalWrite(9,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
}
while(!(S1==LOW && S2==LOW && S3==LOW && S4==LOW && S5==LOW));
}
else if (S1==LOW && S2==HIGH && S3==HIGH && S4==LOW && S5==LOW) //0 1 0 0 0 LEFT TURN & LEFT BEND
{
do
{
Serial.print("LEFT TURN OR BEND");
digitalWrite(10,LOW); //LEFT
digitalWrite(9,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
}
while(!(S1==LOW && S2==LOW && S3==LOW && S4==LOW && S5==LOW));
}
else if (S1==LOW && S2==LOW && S3==HIGH && S4==HIGH && S5==LOW) //0 0 0 1 0 RIGHT TURN & RIHGT BEND
{
do
{
Serial.print("RIGHT TURN OR BEND");
digitalWrite(10,HIGH); //RIGHT
digitalWrite(9,LOW);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
}
while(!(S1==LOW && S2==LOW && S3==LOW && S4==LOW && S5==LOW));
}
else if (S1==LOW && S2==LOW && S3==LOW && S4==HIGH && S5==HIGH) //0 0 1 1 1 ACUTE RIGHT
{
do
{
Serial.print("ACUTE RIGHT");
digitalWrite(10,HIGH); //RIGHT
digitalWrite(9,LOW);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
}
while(!(S1==LOW && S2==LOW && S3==LOW && S4==LOW && S5==LOW));
}
else if (S1==HIGH && S2==HIGH && S3==LOW && S4==LOW && S5==LOW) //1 1 1 0 0 ACUTE LEFT
{
do
{
Serial.print("ACUTE LEFT");
digitalWrite(10,LOW); //LEFT
digitalWrite(9,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
}
while(!(S1==LOW && S2==LOW && S3==LOW && S4==LOW && S5==LOW));
}
else if (S1==LOW && S2==LOW && S3==HIGH && S4==LOW && S5==LOW) //0 0 0 0 0 NO LINE
{
do
{
Serial.print("NO LINE");
digitalWrite(10,HIGH); //RIGHT
digitalWrite(9,LOW);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);HGJ
}
while(!(S1==LOW && S2==LOW && S3==LOW && S4==LOW && S5==LOW));
}
else if (S1==LOW && S2==HIGH && S3==HIGH && S4==HIGH && S5==LOW) //0 1 0 1 0 T JUNCTION
{
do
{
Serial.print("T JUNCTION");
digitalWrite(10,LOW); //LEFT
digitalWrite(9,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
}
while(!(S1==LOW && S2==LOW && S3==LOW && S4==LOW && S5==LOW));
}
}

does aurdino support do_while loop ?

yes, it is just C++

you should remove all thos do while loops as the variables tested in ti are not refreshed

try this

void setup() 
{
    pinMode(10,OUTPUT);
    pinMode(9,OUTPUT);
    pinMode(5,OUTPUT);
    pinMode(6,OUTPUT);

    pinMode(14,INPUT);
    pinMode(15,INPUT);
    pinMode(16,INPUT);
    pinMode(17,INPUT);
    pinMode(18,INPUT);

    Serial.begin(9600);

}

void loop() 
{
    int S1=digitalRead(14);
    int S2=digitalRead(15);
    int S3=digitalRead(16);
    int S4=digitalRead(17);
    int S5=digitalRead(18);

    if(S1==LOW && S2==LOW && S3==LOW && S4==LOW && S5==LOW)   //0 0 1 0 0           NORMAL STRAIGHT
    {
        Serial.print("STRAIGHT");
        digitalWrite(10,LOW);                                //STRAIGHT
        digitalWrite(9,HIGH);
        digitalWrite(5,LOW);
        digitalWrite(6,HIGH);
    }
    else if (S1==LOW && S2==HIGH && S3==LOW && S4==HIGH && S5==LOW)  //0 1 1 1 0       + CROSS
    {
        Serial.print("+ CROSS");
        digitalWrite(10,LOW);                                      //LEFT
        digitalWrite(9,HIGH);
        digitalWrite(5,HIGH);
        digitalWrite(6,LOW);
    }
    else if (S1==LOW && S2==HIGH && S3==LOW && S4==LOW && S5==LOW)   //0 1 1 0 0         LEFT JUNCTION
    {
        Serial.print("LEFT JUNCTION");
        digitalWrite(10,LOW);                                      //LEFT
        digitalWrite(9,HIGH);
        digitalWrite(5,HIGH);
        digitalWrite(6,LOW);
    }
    else if (S1==LOW && S2==LOW && S3==LOW && S4==HIGH && S5==LOW)   //0 0 1 1 0         RIGHT JUNCTION
    {
        Serial.print("RIGHT JUNCTION");
        digitalWrite(10,LOW);                                //STRAIGHT
        digitalWrite(9,HIGH);
        digitalWrite(5,LOW);
        digitalWrite(6,HIGH);
    }
    else if (S1==LOW && S2==HIGH && S3==HIGH && S4==LOW && S5==LOW)   //0 1 0 0 0         LEFT TURN & LEFT BEND
    {
        Serial.print("LEFT TURN OR BEND");
        digitalWrite(10,LOW);                                      //LEFT
        digitalWrite(9,HIGH);
        digitalWrite(5,HIGH);
        digitalWrite(6,LOW);
    }
    else if (S1==LOW && S2==LOW && S3==HIGH && S4==HIGH && S5==LOW)   //0 0 0 1 0         RIGHT TURN & RIHGT BEND
    {
        Serial.print("RIGHT TURN OR BEND");
        digitalWrite(10,HIGH);                                      //RIGHT
        digitalWrite(9,LOW);
        digitalWrite(5,LOW);
        digitalWrite(6,HIGH);
    }
    else if (S1==LOW && S2==LOW && S3==LOW && S4==HIGH && S5==HIGH)   //0 0 1 1 1         ACUTE RIGHT
    {
        Serial.print("ACUTE RIGHT");
        digitalWrite(10,HIGH);                                      //RIGHT
        digitalWrite(9,LOW);
        digitalWrite(5,LOW);
        digitalWrite(6,HIGH);
    }
    else if (S1==HIGH && S2==HIGH && S3==LOW && S4==LOW && S5==LOW)   //1 1 1 0 0         ACUTE LEFT
    {
        Serial.print("ACUTE LEFT");
        digitalWrite(10,LOW);                                      //LEFT
        digitalWrite(9,HIGH);
        digitalWrite(5,HIGH);
        digitalWrite(6,LOW);
    }
    else if (S1==LOW && S2==LOW && S3==HIGH && S4==LOW && S5==LOW)   //0 0 0 0 0         NO LINE
    {
        Serial.print("NO LINE");
        digitalWrite(10,HIGH);                                      //RIGHT
        digitalWrite(9,LOW);
        digitalWrite(5,LOW);
        digitalWrite(6,HIGH);HGJ
    }
    else if (S1==LOW && S2==HIGH && S3==HIGH && S4==HIGH && S5==LOW)   //0 1 0 1 0         T JUNCTION
    {
        Serial.print("T JUNCTION");
        digitalWrite(10,LOW);                                      //LEFT
        digitalWrite(9,HIGH);
        digitalWrite(5,HIGH);
        digitalWrite(6,LOW);
    }
}

and you might replace this block

    {
        Serial.print("STRAIGHT");
        digitalWrite(10,LOW);                                //STRAIGHT
        digitalWrite(9,HIGH);
        digitalWrite(5,LOW);
        digitalWrite(6,HIGH);
    }

with a function

void setMotors(int m1, int m2, int m3, int m4)
    {
        digitalWrite(10, m1);                               
        digitalWrite(9, m2);
        digitalWrite(5, m3);
        digitalWrite(6, m4);
    }

that could condense your code quite a bit e.g.

else if (S1==LOW && S2==HIGH && S3==LOW && S4==LOW && S5==LOW) //0 1 1 0 0
{
Serial.println("LEFT JUNCTION");
setMotors(LOW, HIGH, HIGH, LOW);
}

etc

I HAVE REPLACED THE CODE TO THE FOLLOWING.
BUT ROBO TURNS LEFT AND PRINT "ACUTE RIGHT" IN SERIAL MONITOR WHEN THE SENSORS READ STRAIGHT CONDITION.
PLEASE HELP.

void setup()
{
pinMode(10,OUTPUT);
pinMode(9,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);

pinMode(14,INPUT);
pinMode(15,INPUT);
pinMode(16,INPUT);
pinMode(17,INPUT);
pinMode(18,INPUT);

Serial.begin(9600);

}
void setMotors(int m1,int m2,int m3,int m4)
{
digitalWrite(10,m1);
digitalWrite(9,m2);
digitalWrite(5,m3);
digitalWrite(6,m4);
}

void loop()
{
int S1=digitalRead(14);
int S2=digitalRead(15);
int S3=digitalRead(16);
int S4=digitalRead(17);
int S5=digitalRead(18);

if(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH) //11011 NORMAL STRAIGHT
{
Serial.print("STRAIGHT");
setMotors(LOW,HIGH,LOW,HIGH);
}
else if (S1==HIGH && S2==LOW && S3==LOW && S4==LOW && S5==HIGH) //10001 + CROSS
{
do
{
Serial.print("+ CROSS");
setMotors(LOW,HIGH,HIGH,LOW);
}
while(!(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH));
}
else if (S1==HIGH && S2==LOW && S3==LOW && S4==HIGH && S5==HIGH) //10011 LEFT JUNCTION
{
do
{
Serial.print("LEFT JUNCTION");
setMotors(LOW,HIGH,HIGH,LOW);
}
while(!(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH));
}
else if (S1==HIGH && S2==HIGH && S3==LOW && S4==LOW && S5==HIGH) //11001 RIGHT JUNCTION
{
do
{
Serial.print("RIGHT JUNCTION");
setMotors(LOW,HIGH,LOW,HIGH);
}
while(!(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH));
}
else if (S1==HIGH && S2==LOW && S3==HIGH && S4==HIGH && S5==HIGH) //10111 LEFT TURN & LEFT BEND
{
do
{
Serial.print("LEFT TURN OR BEND");
setMotors(LOW,HIGH,HIGH,LOW);
}
while(!(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH));
}
else if (S1==HIGH && S2==HIGH && S3==HIGH && S4==LOW && S5==HIGH) //11101 RIGHT TURN & RIHGT BEND
{
do
{
Serial.print("RIGHT TURN OR BEND");
setMotors(HIGH,LOW,LOW,HIGH);
}
while(!(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH));
}
else if (S1==HIGH && S2==HIGH && S3==LOW && S4==LOW && S5==LOW) //11000 ACUTE RIGHT
{
do
{
Serial.print("ACUTE RIGHT");
setMotors(HIGH,LOW,LOW,HIGH);
}
while(!(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH));
}
else if (S1==LOW && S2==LOW && S3==LOW && S4==HIGH && S5==HIGH) //00011 ACUTE LEFT
{
do
{
Serial.print("ACUTE LEFT");
setMotors(LOW,HIGH,HIGH,LOW);
}
while(!(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH));
}
else if (S1==HIGH && S2==HIGH && S3==HIGH && S4==HIGH && S5==HIGH) //11111 NO LINE
{
do
{
Serial.print("NO LINE");
setMotors(HIGH,LOW,LOW,HIGH);
}
while(!(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH));
}
else if (S1==HIGH && S2==LOW && S3==HIGH && S4==LOW && S5==HIGH) //10101 T JUNCTION
{
do
{
Serial.print("T JUNCTION");
setMotors(LOW,HIGH,HIGH,LOW);
}
while(!(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH));
}
}

@ nkshaneeb, as a courtesy to people who may be willing to help you please modify your posts to show your program correctly by using the code button </>

so it looks like this

This makes it easy to select and copy to a text editor.

And please don't SHOUT

...R

You are paying a huge price in complexity for not converting the reads to digital. You have so many ifs, elses and whiles that derive from five variables. You can reduce it to one and eliminate all those pesky equality tests. From your comment, //11011, I can see that you realize things are digital. You just need to convert to a number.
Instead of:

void loop()
{
  int S1=digitalRead(14);
  int S2=digitalRead(15);
  int S3=digitalRead(16);
  int S4=digitalRead(17);
  int S5=digitalRead(18);

  if(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH)   //11011           NORMAL STRAIGHT
    {
      Serial.print("STRAIGHT");
      setMotors(LOW,HIGH,LOW,HIGH);
    }

you could do something like this:

byte inputVal;
void loop()
{
inputVal = digitalRead(18);
inputVal |= digitalRead(17) << 1;
inputVal |= digitalRead(16) << 2;
inputVal |= digitalRead(15) << 3;
inputVal |= digitalRead(14) << 4;


  if(inputVal == 11011b)   //11011           NORMAL STRAIGHT
    {
      Serial.print("STRAIGHT");
      setMotors(LOW,HIGH,LOW,HIGH);
    }
//.......and so on...

aarg:
you could do something like this:

  if(inputVal == 11011b)   //11011           NORMAL STRAIGHT

That should be 0b11011.

      do                                                           
        {
        Serial.print("T JUNCTION");
        setMotors(LOW,HIGH,HIGH,LOW);
        }
      while(!(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH));

Since the values of S1 to S5 do not change in the body, you might as well use:

   if(!(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH))        
   {
      do                                                           
      {
        Serial.print("T JUNCTION");
        setMotors(LOW,HIGH,HIGH,LOW);
      }
      while(1);
   }

so that, once the condition becomes true, the while loop spins forever.

By the way, do/while is a pretty stupid choice in this code. A do/while statement does somethig and THEN checks to see if it should have. A while statement checks first.

aarg:
You are paying a huge price in complexity for not converting the reads to digital. You have so many ifs, elses and whiles that derive from five variables. You can reduce it to one and eliminate all those pesky equality tests. From your comment, //11011, I can see that you realize things are digital. You just need to convert to a number.
Instead of:

void loop()

{
 int S1=digitalRead(14);
 int S2=digitalRead(15);
 int S3=digitalRead(16);
 int S4=digitalRead(17);
 int S5=digitalRead(18);

if(S1==HIGH && S2==HIGH && S3==LOW && S4==HIGH && S5==HIGH)   //11011           NORMAL STRAIGHT
   {
     Serial.print("STRAIGHT");
     setMotors(LOW,HIGH,LOW,HIGH);
   }



you could do something like this:


byte inputVal;
void loop()
{
inputVal = digitalRead(18);
inputVal |= digitalRead(17) << 1;
inputVal |= digitalRead(16) << 2;
inputVal |= digitalRead(15) << 3;
inputVal |= digitalRead(14) << 4;

if(inputVal == 11011b)   //11011           NORMAL STRAIGHT
   {
     Serial.print("STRAIGHT");
     setMotors(LOW,HIGH,LOW,HIGH);
   }
//.......and so on...

Better still to use switch instead of a gazillion ifs....

Regards,
Ray L.

I HAVE REPLACED THE CODE TO THE FOLLOWING.

#7 below:

http://forum.arduino.cc/index.php/topic,148850.0.html