Sub routine name not declared?

Hello everyone, I give up. I just don’t understand why I define a subroutine in my simple code and I get the HEATER_CONTROL not define in this scope? Yes I am a beginner. I searched and tried things before posting but I am unable to solve this. I feel I am missing something obvious. Yes I used auto format but no luck. Thank you in advance for the help.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Arduino.h>
#include <TM1637Display.h>
#include <Wire.h>

#define CLK 11
#define DIO 12

#define ONE_WIRE_BUS 8  // TEMP SENSOR

const int buzzer = 9;    //BUZZER
const int relayPin = 2;  // RELAY
const int lowTemp = 97;
const int highTemp = 104;

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
TM1637Display display(CLK, DIO);

void setup(void) {

  delay(2000);

  pinMode(relayPin, OUTPUT);  // PIN 2
  pinMode(buzzer, OUTPUT);    // Set buzzer - pin 9 as an output
  Serial.begin(9600);
  sensors.begin();
}

void loop(void) {

  sensors.requestTemperatures();
  float temperatureF = sensors.getTempFByIndex(0);

  Serial.print("Temperature: ");
  Serial.print(temperatureF);
  Serial.println(" °F");

  display.showNumberDec(temperatureF, false);  // Expect: ___0

  // 3 SECONDS DELAY FOR THE FERMENTING DOTS
  delay(3000);
  delay(5000);

  // Turn the relay ON-OFF

  HEATER_CONTROL();

}


void HEATER_CONTROL(); {

            if (temperatureF > 100.00) {
              digitalWrite(relayPin, HIGH);  // OFF RELAY
            }

            else {
              digitalWrite(relayPin, LOW);  //  ON RELAY
              delay(8000);

              digitalWrite(relayPin, HIGH);  // OFF RELAY
            }

}

C:\BADKID\TECHNICALS\ARDUINO-R4\YOGURT_V2_WORKING_MADE_YOGURT_V6\YOGURT_V2_WORKING_MADE_YOGURT_V6.ino: In function 'void loop()':
C:\BADKID\TECHNICALS\ARDUINO-R4\YOGURT_V2_WORKING_MADE_YOGURT_V6\YOGURT_V2_WORKING_MADE_YOGURT_V6.ino:48:3: error: 'HEATER_CONTROL' was not declared in this scope
lcd.print("FERMENTING");
^~~~~~~~~~~~~~
C:\BADKID\TECHNICALS\ARDUINO-R4\YOGURT_V2_WORKING_MADE_YOGURT_V6\YOGURT_V2_WORKING_MADE_YOGURT_V6.ino:48:3: note: suggested alternative: 'ATTR_CONST'
lcd.print("FERMENTING");
^~~~~~~~~~~~~~
ATTR_CONST
C:\BADKID\TECHNICALS\ARDUINO-R4\YOGURT_V2_WORKING_MADE_YOGURT_V6\YOGURT_V2_WORKING_MADE_YOGURT_V6.ino: At global scope:
C:\BADKID\TECHNICALS\ARDUINO-R4\YOGURT_V2_WORKING_MADE_YOGURT_V6\YOGURT_V2_WORKING_MADE_YOGURT_V6.ino:53:24: error: expected unqualified-id before '{' token
lcd.setCursor(12, 0);
^
exit status 1

Compilation error: 'HEATER_CONTROL' was not declared in this scope

See the extraneous semicolon? Lose it and try again.

2 Likes

Auto format does not fix errors. It makes the code easier for humans to read and help them to spot errors that the compiler cannot spot. But it doesn't look like you used auto format anyway.

Please post error listings in code tags.

@van_der_decken 's suggestion should fix the problem, but only because the Arduino IDE let's you do something you should never do: use/call a function before declaring it. You are not allowed to use a variable before you declare it. You should not use a function before you declare it either. Add your own functions before setup() and loop().

I tried to remove the semi colum same error. I moved the subroutine above setup and loop. error out.

Sorry guys I don’t get this one. Even example like void loop() {
do something; subroutinename(); ←—– have a semi column. Thank you for your patience.

here is the code without ;

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Arduino.h>
#include <TM1637Display.h>
#include <Wire.h>

#define CLK 11
#define DIO 12

#define ONE_WIRE_BUS 8  // TEMP SENSOR

const int buzzer = 9;    //BUZZER
const int relayPin = 2;  // RELAY
const int lowTemp = 97;
const int highTemp = 104;

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
TM1637Display display(CLK, DIO);


void setup(void) {

  delay(2000);

  pinMode(relayPin, OUTPUT);  // PIN 2
  pinMode(buzzer, OUTPUT);    // Set buzzer - pin 9 as an output
  Serial.begin(9600);
  sensors.begin();
}

void loop(void) {

  sensors.requestTemperatures();
  float temperatureF = sensors.getTempFByIndex(0);

  Serial.print("Temperature: ");
  Serial.print(temperatureF);
  Serial.println(" °F");

  display.showNumberDec(temperatureF, false);  // Expect: ___0

  // 3 SECONDS DELAY FOR THE FERMENTING DOTS

  delay(5000);

  // Turn the relay ON-OFF

  HEATER_CONTROL()
 
 }  // LOOP 

  void HEATER_CONTROL(); {

    if (temperatureF > 100.00) {
      digitalWrite(relayPin, HIGH);  // OFF RELAY
    }

    else {
      digitalWrite(relayPin, LOW);  //  ON RELAY
      delay(8000);

      digitalWrite(relayPin, HIGH);  // OFF RELAY
    }
  }


You removed the wrong semicolon. It should look like:

 HEATER_CONTROL();
 
 }  // LOOP 

void HEATER_CONTROL() {
1 Like

man i feel dumb. Sorry! and thank you. Tomorrow I can continue organizing the code!

Before:

After:

Apparently it's necessary to add "remove the extraneous semicolon FROM THIS LINE, NOT SOME OTHER LINE".

1 Like

Sorry long day. Thanks for the help