Error by compiling

Hello Experts
I've got a little problem with my Arduino code.

I have two .ino files in the same folder (Function file + Normal Loop and Setup file).

Now I'm trying to compile them, but I get a lot of errors.

Can anybody help me?

I added the files in the Zip folder below.

I get following error:

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\roethlisbergerstefan\Desktop\ArduinoWateringSystem\ArduinoWateringSystem.ino: In function 'void loop()':

ArduinoWateringSystem:44: error: 'getWaterBreakeStatus' was not declared in this scope

waterBreakStatus = getWaterBreakeStatus();

^

ArduinoWateringSystem:45: error: 'getLightSensor' was not declared in this scope

lightStatus = getLightSensor();

^

ArduinoWateringSystem:50: error: 'waterSensorValue' was not declared in this scope

waterSensorValue = getSensorValue();

^

ArduinoWateringSystem:50: error: 'getSensorValue' was not declared in this scope

waterSensorValue = getSensorValue();

^

ArduinoWateringSystem:118: error: 'sendAndroidValues' was not declared in this scope

sendAndroidValues();

^

functions:4: error: a function-definition is not allowed here before '{' token

{

^

functions:9: error: a function-definition is not allowed here before '{' token

{

^

functions:62: error: expected '}' at end of input

}

^

exit status 1
'getWaterBreakeStatus' was not declared in this scope

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

ArduinoWateringSystem.zip (22.4 KB)

Why don't post the error? :slight_smile:

And when did you starting to get errors?

I added the code at the error in the description

 bool getWaterBreakeStatus()
 {
   WaterBreakSensorValue = analogRead(WaterBreakSensor);

Whey ies theree aen extrea e ien thee functioen namee?

Consistent placement of curly braces would help. Sometimes they are on new lines (where they belong) and sometimes they are on the line with the function/statement.

Where does loop() end?

At least the main .ino is formatted correct (HINT!).

But uhm, where does the loop end? :wink:

This is the Loop end in the Main function

void loop() {
  waterBreakStatus = getWaterBreakeStatus();
  lightStatus = getLightSensor();
  hum = dht.readHumidity();
  temp = dht.readTemperature();
  if (waterBreakStatus == false)
  {
    waterSensorValue = getSensorValue();
    if (waterSensorValue >= 301 && waterSensorValue <= 450)
    {
      digitalWrite(RelayPump, LOW);
    }
    else if (waterSensorValue >= 451)
    {
      digitalWrite(RelayPump, HIGH);
    }
  }

  if (lightStatus == true)
  {
    digitalWrite(RelayVentilator, LOW);
  }
  else
  {
    if (millis() - previousMillis > interval && ventilatorStarted == false)
    {
      previousMillis = millis();
      if (lastValue == true)
      {
        if (hum >= 50 || temp >= 26)
        {
          digitalWrite(RelayVentilator, HIGH);
          started = true;
        }
        else if (started == true)
        {
          started = false;
          digitalWrite(RelayVentilator, LOW);
        }

      }
      else
      {
        if (hum >= 60 || temp >= 24)
        {
          started = true;
          digitalWrite(RelayVentilator, HIGH);
        }
        else if (started == true)
        {
          started = false;
          digitalWrite(RelayVentilator, LOW);
        }
      }
    }
    if (millis() - previousVentilatorMillis > intervalVentilatorStart && started == false)
    {
      if (ventilatorStarted == false)
      {
        digitalWrite(RelayVentilator, HIGH);
        ventilatorStarted == true;
        ventilatorMillis = millis();
      }
      else if (ventilatorStarted == true && millis() - ventilatorMillis > interval )
      {
        digitalWrite(RelayVentilator, LOW);
        ventilatorStarted == false;
        previousVentilatorMillis = millis();
      }
    }
    Serial.print("Humidity: ");
    Serial.print(hum);
    Serial.print(" %, Temp: ");
    Serial.print(temp);
    Serial.println(" Celsius");
    sendAndroidValues();
  }

So that should be ok or not ?

A really useful tool for troubleshooting is the Arduino IDE's Tools > Auto Format. After doing the Auto Format you can check the indentation of your code to see if it matches your intended program structure. You'll notice that the last closing brace is indented. That's a sure sign of a problem since the closing brace of function should never be indented.

Look again :wink:

At what indent does loop start? And at what indent do you think it ends?

You can see the matching bracket by putting the cursor next to it :wink:

I'm such an idiot :smiley:
Thank you..

But now I'm receiving following Error:

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\roethlisbergerstefan\Desktop\ArduinoWateringSystem\ArduinoWateringSystem.ino: In function 'void loop()':

ArduinoWateringSystem:49: error: 'waterSensorValue' was not declared in this scope

waterSensorValue = getSensorValue();

^

ArduinoWateringSystem:49: error: 'getSensorValue' was not declared in this scope

waterSensorValue = getSensorValue();

^

C:\Users\roethlisbergerstefan\Desktop\ArduinoWateringSystem\functions.ino: In function 'bool getLightSensor()':

functions:10: error: 'getLightSensorValue' was not declared in this scope

getLightSensorValue = analogRead(LightSensor);

^

C:\Users\roethlisbergerstefan\Desktop\ArduinoWateringSystem\functions.ino: In function 'bool getWaterBreakeStatus()':

functions:22: error: 'WaterBreakSensorValue' was not declared in this scope

WaterBreakSensorValue = analogRead(WaterBreakSensor);

^

functions:22: error: 'WaterBreakSensor' was not declared in this scope

WaterBreakSensorValue = analogRead(WaterBreakSensor);

^

exit status 1
'waterSensorValue' was not declared in this scope

I think the compiler doesn't finde the functions in the other .ino file, is this ture?

flaeckli:
I think the compiler doesn't finde the functions in the other .ino file, is this ture?

No, not at all. None of those errors have anything to do with functions. It's reporting undeclared variables. Where in your code did you declare those variables?

Use File + Preferences. Check the Enable Verbose mode for compiling box. Verify your code again.

Look at the output. It will tell you where the files being compiled were copied. Go to that location, and find the cpp file that the IDE created from your ino files. Show us that file.