expected ';' before 'if', expected primary-expression before 'for' etc...

Hi!

I am quite new to arduino and programming, but have a few things I need to operate automatically in my master project. I am doing temperature cycling tests in water, where the sequence of the test is as follows:

  • A valve is opened to let cold water into a container. The valve will close when the container is full (this is timed, no sensors for this). Nothing happens for 1 hour.
  • A heater is turned on. To keep the temperature of the water constant at 90 deg, the heater will go on or off according to temperature readings from a thermocouple. (Not quite sure which brand of the thermocouple I will use, so this part of the code will most likely need some alterations later). The heating process lasts 1 hour.
  • To start the cooling process again, a second valve is opened and is kept open for a certain amount of time.

Then the process can start over again. I want the three functions Cool, Heat and Empty to be on in a sequence/loop, while the temperature should be measured every minute or so.

I have used the BlinkWithoutDelay and SeveralThingsAtTheSameTime as basis for my code, but i get a lot of errors like "expected ‘;’ before ‘if’ ", but as far as i can see there are no ‘;’ missing. Any ideas on how to fix this?

Also, since my actions are time-related I tried to use for-expressions in my loop and to call functions from there. Hopefully that is a good way to do it, but any tips on how to improve my code are greatly appreciated!

int valve1 = 0;    //water in
int valve2 = 1;    //water out
int heater = 2;    //heater

int thermo = 3;       //This is the Arduino Pin that will read the sensor output
int sensorInput;      //The variable we will use to store the sensor input
int temperature;      //The variable we will use to store temperature in degrees.         these three things will read the thermocouple

unsigned long currentMillis;         // stores the value of millis() in each iteration of loop()
unsigned long previousMillis = 0;          // will store last time an action was started
unsigned long interval = 3600000;          // duration of each action = 1 hr
unsigned long waterin = 20000;             // keep valvein open for 20 seconds
unsigned long waterout = 20000;            // keep valveout open for 20 seconds

//========================================

void setup() {

  Serial.begin(9600); //Start the Serial Port at 9600 baud (default)

  pinMode(valve1, OUTPUT);            //Sets the pin as an output
  pinMode(valve2, OUTPUT);
  pinMode(heater, OUTPUT);
  pinMode(thermo, OUTPUT);

}

//========================================

void loop() {

  sensorInput = analogRead(3);             //read the analog sensor and store it
  thermo = (double)sensorInput / 1024;     //find percentage of input reading
  thermo = thermo * 5;                     //multiply by 5V to get voltage
  thermo = thermo - 0.5;                   //Subtract the offset
  thermo = thermo * 100;                   //Convert to degrees


  Serial.print("Current Temperature: ");
  Serial.println(temperature);


  currentMillis = millis();

  for (currentMillis - previousMillis < interval)
  {
    Cool();
    previousMillis = currentMillis;
  }

  for (currentMillis - previousMillis < interval)
  {
    Heat();
    previousMillis = currentMillis;
  }

  for (currentmillis - previousMillis < waterOut)
  {
    Empty();
    previousMillis = 0;
  }


  //=========================================


  //open valve to fill the container with cold water. shut the valve when full, and wait for 1 hr.
  void Cool() {

    if (valve2 == LOW) 
    {
      valve1 = HIGH;
    }
    else 
    {
      valve1 = LOW;
    }

    if (currentMillis - previousMillis > waterin)
    {
      valve1 = LOW;
    }
    else 
    {
      valve1 = HIGH;
    }

  }
}

//=========================================


// turn the heater ON. When the temperature is above 90 deg, turn the heater OFF. If below 90 (or like 86?), turn the heater ON again. Keep doing this for 1 hour.
void Heat() {

  if (temperature < 90)
  {
    heater = HIGH;
  }
  else 
  {
    heater = LOW;
  }

  if (temperature > 90)
  {
    heater = LOW;
  }
  else 
  {
    heater = HIGH;
  }
}
}

//=========================================

void Empty() {
  valve2 = HIGH; 
  {
    if (currentMillis - previousMillis >= waterin) 
    {
      valve2 = LOW;
    }
    else 
    {
      valve2 = HIGH;
    }
    delay(600000); //delay for 10 minutes
  }
}

This are the errors I get:

C:\Arduino\master\thermalcycling\thermalcycling.ino: In function 'void loop()':

thermalcycling:47:49: error: expected ';' before ')' token

   for (currentMillis - previousMillis < interval) 

                                                 ^

thermalcycling:53:3: error: expected primary-expression before 'for'

   for (currentMillis - previousMillis < interval) 

   ^

thermalcycling:53:3: error: expected ';' before 'for'

thermalcycling:53:3: error: expected primary-expression before 'for'

thermalcycling:53:3: error: expected ')' before 'for'

thermalcycling:53:49: error: expected ';' before ')' token

   for (currentMillis - previousMillis < interval) 

                                                 ^

thermalcycling:59:3: error: expected primary-expression before 'for'

   for (currentmillis - previousMillis < waterOut) 

   ^

thermalcycling:59:3: error: expected ';' before 'for'

thermalcycling:59:3: error: expected primary-expression before 'for'

thermalcycling:59:3: error: expected ')' before 'for'

thermalcycling:59:8: error: 'currentmillis' was not declared in this scope

   for (currentmillis - previousMillis < waterOut) 

        ^

thermalcycling:59:41: error: 'waterOut' was not declared in this scope

   for (currentmillis - previousMillis < waterOut) 

                                         ^

thermalcycling:72:5: error: expected primary-expression before 'if'

     if (valve2 == LOW) {

     ^

thermalcycling:72:5: error: expected '}' before 'if'

thermalcycling:72:5: error: function 'void Cool()' is initialized like a variable

thermalcycling:72:5: error: expected ';' before 'if'

thermalcycling:72:5: error: expected primary-expression before 'if'

thermalcycling:72:5: error: expected ')' before 'if'

C:\Arduino\master\thermalcycling\thermalcycling.ino: At global scope:

thermalcycling:86:1: error: expected declaration before '}' token

 }

 ^

exit status 1
expected ';' before ')' token

thermalcycling.ino (3.04 KB)

Look up C++ for statements - they have three clauses, separated by semicolons. Yours don't, which is what the compiler is complaining about.

Perhaps a while statement is what you're looking for?