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 :-
- Digital pin 12 connected to B2 of motor driver.
- Digital pin 13 connected to B1 of motor driver.
- Digital pin 11 connected to A1 of motor driver.
- Digital pin 10 connected to A2 of motor driver.
- Analog Pin A1 connected to left sensor .
- 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.