function was not declared in this scope(Solved)

hello I am using an arduino UNO board stacked with a motor driver shield l239D and I want to make a line follower robot using 3 IR sensors. However when I try to compile this code it gives me the error:""left" was not declared in this scope". I know that this is a very frequent error an it is because of the function declaration but I tried everything and it still doesn t work.

Here is my code:

#include<AFMotor.h>

#define left_sen A0 
#define center_sen A2 
#define right_sen A1

 
//data_sheet
// constants that are used in the code. lineStandard is the level to detect 
// if the sensor is on the line or not. If the sensor value is greater than this
// the sensor is above a DARK line.


AF_DCMotor motor1(1, MOTOR12_1KHZ); 
AF_DCMotor motor4(4, MOTOR12_1KHZ);

int lineStandard = 800;



void setup()
{ 

pinMode(right_sen, INPUT); 
pinMode(center_sen, INPUT); 
pinMode(left_sen, INPUT); 

}

void loop()
{ 
  

  //data_sheet
  // if the line is under the right sensor, adjust relative speeds to turn to the right
 if(analogRead (right_sen) > lineStandard)
  {
  left();
  }
  //data_sheet
  // if the line is under the left sensor, adjust relative speeds to turn to the left
 if(analogRead (left_sen) > lineStandard)
  {//right
  right();
  }
  //data_sheet
  // if all sensors are on black or up in the air, stop the motors.
  // otherwise, run motors given the control speeds above.
  if((analogRead (left_sen) > lineStandard) && (analogRead (center_sen)> lineStandard) && (analogRead (right_sen) > lineStandard) )
  {
    //stop
    Stop ();
  }
  else
  {
  //any dir
    forward();
  }
  delay(0);  // add a delay to decrease sensitivity.
}
  
}
void right() {
 motor1.run(FORWARD); 
 motor1.setSpeed(150); 
 motor4.run(BACKWARD); 
 motor4.setSpeed(150);  

}
void Stop () 
{
 motor1.run(RELEASE); 
 motor4.run(RELEASE); 
}
void left() {
  motor1.run(BACKWARD);
  motor1.setSpeed(150); 
  motor4.run(FORWARD); 
  motor4.setSpeed(150);  
}
void forward() {
  motor1.run(FORWARD); 
  motor1.setSpeed(120); 
  motor4.run(FORWARD); 
  motor4.setSpeed(120); 
}

}

I already tried declaring my "left()" in void setup(), after the libary but it still doesn t work. Im sure it is something stupid but I dont know.

Kindly help.

i wasn't able to reproduce your error. it may help if you can post the error message. it's seems odd that if you get only get an error for "left()"

however, there is an extra "}" at the bottom of your code.

Thanks for your answer however someone just message me the solution it was really the "{".

Thank you.

Now that I have the answer how do i delete the question?

Now that I have the answer how do i delete the question?

You don't You leave the topic as it is to help people in the future

3 Likes