Wanted to build a obstacle avioder robot using 2 IR sensor

HELLO I AM TRYING TO BUILD A OBSTACLE AVIODER ROBOT USING 2 IR SENSOR and 2 dc motors, 1 L293 motor driver

Pin specification for arduino uno :-

  1. Digital pin 12 connected to B2 of motor driver.
  2. Digital pin 13 connected to B1 of motor driver.
  3. Digital pin 11 connected to A1 of motor driver.
  4. Digital pin 10 connected to A2 of motor driver.
  5. Analog Pin A1 connected to left sensor .
  6. Analog Pin A0 connected to right sensor.

programming

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600); // Begins the Serial Communication with Baud rate 9600.
pinMode(10,OUTPUT); // Sets the Pins 10, 11, 12, 13 as OUTPUT Pins.
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(A0, INPUT); // Sets the Analog Pins A0 and A1 as INPUT Pins.
pinMode(A1, INPUT);
}

/* A function is a way for programmers to reuse code without having to rewrite the code
 *  Syntax : returntype functionName(arguments){
 *            // function body
 *            return returntype;
 *            }
 */

void moveRobot(String motion){

  if(motion == "Forward"){  // RW - Fwd(10 - Pos, 11 - Neg); LW - Fwd(12 - Pos, 13 - Neg)
    digitalWrite(10,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
    Serial.println("Forward");
  }

  if(motion == "Backward"){  // RW - Bck(10 -Neg, 11 - Pos); LW - Bck(12 -Neg, 13 - Pos)
    digitalWrite(10,LOW);
    digitalWrite(11,HIGH);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
    Serial.println("Backward");
  }

  if(motion == "Left"){  // RW -Fwd(10 -  Pos, 11 - Neg); LW - Bck(12 -Neg, 13 - Pos)
    digitalWrite(10,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,HIGH);
    Serial.println("LEFT");
  }

   if(motion == "Right"){  // RW -Bck(10 - Neg, 11 - Pos); LW - Fwd(12 -Pos, 13 - Neg)
    digitalWrite(10,LOW);
    digitalWrite(11,HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(13,LOW);
    Serial.println("Right");
  }

   if(motion == "Stop"){  // RW -Stop(10 - Neg, 11 - Pos); LW - Fwd(12 -Pos, 13 - Neg)
    digitalWrite(10,LOW);
    digitalWrite(11,LOW);
    digitalWrite(12,LOW);
    digitalWrite(13,LOW);
    Serial.println("Stop");
  }

}


void loop() {
  // put your main code here, to run repeatedly:
int Right = analogRead(A0); //Reads the Analog Value on Pin A0 and store it in "Right".
int Left = analogRead(A1); //Reads the Analog Value on Pin A1 and store it in "Left".
Serial.print("Value of Right sensor : " + String(Right));
Serial.print("\t"); //Gives a tab space.
Serial.println("Value of Left sensor : " + String(Left));
delay(1000);
if((Right > 600)) && (Left > 600)){ //Both Sensors detect an Obstacle.
  moveRobot("Stop");
  delay(1000);
  moveRobot("Backward");
  delay(1000);
  moveRobot("Left");
  delay(2000);
}
if((Right < 600)) && (Left < 600)){ //Both Sensors  doesnot detect any Obstacle.
  
  moveRobot("Forward");
  }
  if((Right < 600)) && (Left > 600)){ //Left Sensors detects an Obstacle. Robot move towards Right Direction.
  moveRobot("Stop");
  delay(1000);
  moveRobot("Backward");
  delay(1000);
  moveRobot("Right");
  delay(1000);
}
if((Right > 600)) && (Left < 600)){ //Right Sensors detect an Obstacle. Robot move towards Left Direction.
  moveRobot("Stop");
  delay(1000);
  moveRobot("Backward");
  delay(1000);
  moveRobot("Left");
  delay(1000);
}
}

PLEASE HELP I AM A NEWBIE.....
OUTPUT
Arduino: 1.8.16 (Windows 8.1), Board: "Arduino Uno"

C:\Users\shanetec\Desktop\arduino program\obstacle\obstacle.ino: In function 'void loop()':

obstacle:72:22: error: expected identifier before '(' token

if((Right > 600)) && (Left > 600)){ //Both Sensors detect an Obstacle.

                  ^

obstacle:80:22: error: expected identifier before '(' token

if((Right < 600)) && (Left < 600)){ //Both Sensors doesnot detect any Obstacle.

                  ^

obstacle:84:24: error: expected identifier before '(' token

if((Right < 600)) && (Left > 600)){ //Left Sensors detects an Obstacle. Robot move towards Right Direction.

                    ^

obstacle:92:22: error: expected identifier before '(' token

if((Right > 600)) && (Left < 600)){ //Right Sensors detect an Obstacle. Robot move towards Left Direction.

                  ^

exit status 1

expected identifier before '(' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Make sure your ( match your )

(Crazy use of Strings, BTW)

...every ( should have a matching )

Meaning where i have to change and what is the change

Everywhere the compiler told you you have a problem.

Sorry i don't able to understand what do you mean by match here

I mean, if you've got one of these ( there should be only one ) to match it

The second ) in all of these...

if ((Right < 600))

... closes the whole "if". So lose one, and go:

if ((Right < 600)

1 Like

Count the (, then count the )

Hi,
You should have matching;
right facing brackets like this (
to
left facing brackets like this )

Count the number of ( and ) in this line;

  if ((Right > 600)) && (Left < 600)) //Right Sensors detect an Obstacle. Robot move towards Left Direction.

Just the fault in 4 lines of your code has generated all the errors, because the ( and ) don't match.

Tom... :grinning: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.