Arduino mega programing error

could any one help my solve this Problem,i am working on fire fighting robot
i write the arduino code but still give me ''brake' was not declared in this scope''
my code is below:

#include <Servo.h>

float pi=3.14159;
float posv=0;
int Ftop = 28;
int motorA1 = 9;
int motorA2 = 11;
int motorB1 = 6;
int motorB2 = 5;
int Faleft=0;
int Famid=0;
int Faright=0;
int Fdmid = 52;
int Fdright = 50;
int Fdleft = 48;
//Right Ultrasonic
int trig1 = 43;
int echo1 = 45;
long duration1;
int distance1;
long duration2;
int distance2;
int pump=2;
int pos=0;
//Left Ultrasonic
int trig2 = 47;
int echo2 = 49;

Servo vertiservo;
Servo horizservo;

void setup() {

pinMode(Ftop,INPUT);
pinMode(trig1,OUTPUT);
pinMode(echo1,INPUT);
pinMode(trig2,OUTPUT);
pinMode(echo2,INPUT);
pinMode(motorA1,OUTPUT);
pinMode(motorA2,OUTPUT);
pinMode(motorB1,OUTPUT);
pinMode(motorB2,OUTPUT);
pinMode(Fdmid,INPUT);
pinMode(Fdright,INPUT);
pinMode(Fdleft,INPUT);
pinMode(pump,OUTPUT);
horizservo.write(30);
// wifisetup();

Serial.begin(9600);
}

void loop() {

Famid=analogRead(A12);
Faright=analogRead(A13);
Faleft=analogRead(A14);
Fdmid=digitalRead(52);
Fdright=digitalRead(50);
Fdleft=digitalRead(48);
Ftop=digitalRead(28);
// Serial.print("mid :");
//Serial.println(Famid);
// Serial.print("distright :");
// Serial.println(Faright);
// Serial.print("distleft :");
// Serial.println(Faleft);
//ultrasonic 1

// Clears the trig1
digitalWrite(trig1, LOW);
delayMicroseconds(2);
digitalWrite(trig1, HIGH); // Sets the trigPin on HIGH state for 10 micro seconds
delayMicroseconds(10);
digitalWrite(trig1, LOW);// Reads the echoPin, returns the sound wave travel time in microseconds
duration1= pulseIn(echo1, HIGH);
// Calculating the distance
distance1= duration1*0.034/2;
// Prints the distance on the Serial Monitor
//Serial.print("Distance ult1: ");
//Serial.println(distance1);

//ultrasonic 2

// Clears the trig2
digitalWrite(trig2, LOW);
delayMicroseconds(2);
digitalWrite(trig2, HIGH); // Sets the trigPin on HIGH state for 10 micro seconds
delayMicroseconds(10);
digitalWrite(trig2, LOW);// Reads the echoPin, returns the sound wave travel time in microseconds
duration2= pulseIn(echo2, HIGH);
// Calculating the distance
distance2= duration2*0.034/2;
// Prints the distance on the Serial Monitor

// Serial.print("Distance ult2: ");
//Serial.println(distance2);

if (Fdmid==LOW ){

if (Ftop==LOW){
brake();

// wifisend();
pumpstart();
aim();
delay(100);
pumpstop();
}
else{
if (distance2<10){
leftUltra();
}

  else if (distance1<10){
    rightUltra();
    }
      
  else {
    forward();
     
  
  }}}

else {
brake();
right();
while(digitalRead(52)==HIGH)
{}
}}

Please edit your post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.

Did it occur to you that the code for many functions, like the "brake()" that caused that error, is actually missing from the sketch?

Where is your brake() function ?

Also right(), ultraRight(), forward(), pumpstop(), etc etc...

While we're on the subject of scope . . . :wink:

I'm a little confused could you help me identify them

Look at the errors that you get; scroll through the output window

C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_763798\sketch_oct16a.ino: In function 'void loop()':

sketch_oct16a:102: error: 'brake' was not declared in this scope

       brake();

       ^~~~~

sketch_oct16a:105: error: 'pumpstart' was not declared in this scope

       pumpstart();

       ^~~~~~~~~

C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_763798\sketch_oct16a.ino:105:7: note: suggested alternative: 'va_start'

       pumpstart();

       ^~~~~~~~~

       va_start

sketch_oct16a:106: error: 'aim' was not declared in this scope

       aim();

       ^~~

sketch_oct16a:108: error: 'pumpstop' was not declared in this scope

       pumpstop();

       ^~~~~~~~

C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_763798\sketch_oct16a.ino:108:7: note: suggested alternative: 'pump'

       pumpstop();

       ^~~~~~~~

       pump

sketch_oct16a:112: error: 'leftUltra' was not declared in this scope

         leftUltra();

         ^~~~~~~~~

sketch_oct16a:116: error: 'rightUltra' was not declared in this scope

         rightUltra();

         ^~~~~~~~~~

sketch_oct16a:120: error: 'forward' was not declared in this scope

         forward();

         ^~~~~~~

C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_763798\sketch_oct16a.ino:120:9: note: suggested alternative: 'fread'

         forward();

         ^~~~~~~

         fread

sketch_oct16a:128: error: 'brake' was not declared in this scope

     brake();

     ^~~~~

sketch_oct16a:129: error: 'right' was not declared in this scope

     right();

     ^~~~~

C:\Users\sterretje\AppData\Local\Temp\arduino_modified_sketch_763798\sketch_oct16a.ino:129:5: note: suggested alternative: 'Fdright'

     right();

     ^~~~~

     Fdright

Using library Servo at version 1.1.2 in folder: C:\Program Files (x86)\Arduino\libraries\Servo 
exit status 1
'brake' was not declared in this scope

Every function must have some code to define it. This should not be a surprise, except that some function code is hidden in libraries and core code. It's possible that those functions are defined for you in some library or include file that you forgot (or didn't realize that you needed) to include with the #include statement.

Or, you just went and cut and pasted a bunch of code you found on the internet without understanding it very much. Therefore, forgot to cut and paste those functions.

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