Compiling timer problems

Ahh yes, the same old cliche "my first project", well it is, and I have swallowed my pride and calling for help!
The project
A unit to control the temperature and humility in a cupboard for drying cloths using a liquid filled tube heater and an extract fan for when the humidity is too high, these will operate through relays. I have used codes that I have found on the net and the temp/hum sensors working the relays and displayed on the LCD all works fine.
What I want to do now is add a timer to it that will display on the LCD, when it reaches '0' will turn off the heater. This is what I thought would be then easy part but is proving not to be. Now I have found various sketches to do this but when I integrate it into the excising code it becomes a bit out of my league, attached is what I have so far and is also open to change and suggestions. Thanks.

#include <DHT22.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

#define DHT22_PIN 2
int temp_relayPin = 13;
int hum_relayPin = 4;

// Temp/Humidity sensor
DHT22 myDHT22(DHT22_PIN);

void setup()
{
pinMode(temp_relayPin, OUTPUT);
pinMode(hum_relayPin, OUTPUT);

lcd.begin(16, 2);

Serial.begin(9600);
Serial.println("DHT22 Library Demo");
lcd.print("Please Wait.........");
}

void loop(void)
{
temp_updateOutputs();
hum_updateOutputs();
DHT22_ERROR_t errorCode;

delay(2000);
Serial.print("Requesting data...");
errorCode = myDHT22.readData();
switch(errorCode)
{
case DHT_ERROR_NONE:
lcd.begin(16,2);
Serial.print("Got Data ");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Hum% TempC TimeM");
lcd.setCursor(0,1);
lcd.print(myDHT22.getHumidity());
lcd.setCursor(6,1);
lcd.print(myDHT22.getTemperatureC());

break;
case DHT_ERROR_CHECKSUM:
Serial.print("check sum error ");
Serial.print(myDHT22.getTemperatureC());
Serial.print("C ");
Serial.print(myDHT22.getHumidity());
Serial.println("%");
break;
case DHT_BUS_HUNG:
Serial.println("BUS Hung ");
break;
case DHT_ERROR_NOT_PRESENT:
Serial.println("Not Present ");
break;
case DHT_ERROR_ACK_TOO_LONG:
Serial.println("ACK time out ");
break;
case DHT_ERROR_SYNC_TIMEOUT:
Serial.println("Sync Timeout ");
break;
case DHT_ERROR_DATA_TIMEOUT:
Serial.println("Data Timeout ");
break;
case DHT_ERROR_TOOQUICK:
Serial.println("Polled to quick ");
break;
}
}

void temp_updateOutputs()
{
if (myDHT22.getTemperatureC() < 25)
{
digitalWrite(temp_relayPin, HIGH);
}
else if (myDHT22.getTemperatureC() > 25)
{
digitalWrite(temp_relayPin, LOW);
}
}

void hum_updateOutputs()
{
if (myDHT22.getHumidity() < 58)
{
digitalWrite(hum_relayPin, LOW);
}
else if (myDHT22.getHumidity() > 58)
{
digitalWrite(hum_relayPin, HIGH);
}
}

I have decided that I will no longer be responding to topics that are polls, unless the poll is properly soliciting opinions.

The button for posting a thread was right next to the one for posting a poll. It should have been perfectly obvious that a poll was not what you wanted when the poll questions didn't make sense.

I have decided that I will no longer be responding to topics that are polls, unless the poll is properly soliciting opinions.

The button for posting a thread was right next to the one for posting a poll. It should have been perfectly obvious that a poll was not what you wanted when the poll questions didn't make sense.

I first posted this as a poll for which I apologize this is; "my first project", and I have swallowed my pride and calling for help!
The project:
A unit to control the temperature and humility in a cupboard for drying cloths using a liquid filled tube heater and an extract fan for when the humidity is too high, these will operate through relays. I have used codes that I have found on the net and the temp/hum sensors working the relays and displayed on the LCD all works fine.
What I want to do now is add a timer to it that will display on the LCD, when it reaches '0' will turn off the heater. This is what I thought would be then easy part but is proving not to be. Now I have found various sketches to do this but when I integrate it into the excising code it will not compile I have tried everything in my knowledge (very limited when it comes to programing) with the same result, attached is what I have so far including timer this is open to change and suggestions. Thanks.

#include <DHT22.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

#define DHT22_PIN 2
int temp_relayPin = 13;
int hum_relayPin = 4;
int runTimer = 1;
int timer_relayPin = 5;

// Temp/Humidity sensor
DHT22 myDHT22(DHT22_PIN);

void setup()
{
pinMode(temp_relayPin, OUTPUT);
pinMode(hum_relayPin, OUTPUT);
{
pinMode(timer_relayPin, OUTPUT);
}
lcd.begin(16, 2);

Serial.begin(9600);
Serial.println("DHT22 Library Demo");
lcd.print("Please Wait.........");
}

void loop(void)
{
if(runTimer == 1) // rum timer once//

{
timer(); // start timer //
}
runTimer = 0;
{
digitalWrite(timer_relayPin, HIGH);
}
}

{
temp_updateOutputs();
hum_updateOutputs();
DHT22_ERROR_t errorCode;

delay(2000);
Serial.print("Requesting data...");
errorCode = myDHT22.readData();
switch(errorCode)
{
case DHT_ERROR_NONE:
lcd.begin(16,2);
Serial.print("Got Data ");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Hum% TempC TimeM");
lcd.setCursor(0,1);
lcd.print(myDHT22.getHumidity());
lcd.setCursor(6,1);
lcd.print(myDHT22.getTemperatureC());

break;
case DHT_ERROR_CHECKSUM:
Serial.print("check sum error ");
Serial.print(myDHT22.getTemperatureC());
Serial.print("C ");
Serial.print(myDHT22.getHumidity());
Serial.println("%");
break;
case DHT_BUS_HUNG:
Serial.println("BUS Hung ");
break;
case DHT_ERROR_NOT_PRESENT:
Serial.println("Not Present ");
break;
case DHT_ERROR_ACK_TOO_LONG:
Serial.println("ACK time out ");
break;
case DHT_ERROR_SYNC_TIMEOUT:
Serial.println("Sync Timeout ");
break;
case DHT_ERROR_DATA_TIMEOUT:
Serial.println("Data Timeout ");
break;
case DHT_ERROR_TOOQUICK:
Serial.println("Polled to quick ");
break;
}
}

void temp_updateOutputs() // runs heater on and off through relay //
{
if (myDHT22.getTemperatureC() < 40)
{
digitalWrite(temp_relayPin, HIGH);
}
else if (myDHT22.getTemperatureC() > 40)
{
digitalWrite(temp_relayPin, LOW);
}
}

void hum_updateOutputs() // runs extract fan on and off through relay //
{
if (myDHT22.getHumidity() < 70)
{
digitalWrite(hum_relayPin, LOW);
}
else if (myDHT22.getHumidity() > 70)
{
digitalWrite(hum_relayPin, HIGH);
}
}
void timer() // runs timer, will swith power off to heater through relay once timer runs out //
{
for(int timer =180; timer > 0; --timer) // timer set to run for 180 minutes /
{
if(timer >= 10)
lcd.setCursor(13,1);
else{
lcd.setCursor(13,1);
lcd.print("0");
lcd.setCursor(14,1);
}
lcd.print(timer);
lcd.print(" ");
delay(60000);
}
}

What is the compiler complaining about?

The error is:

sketch_oct30a:42: error: expected unqualified-id before '{' token

For:

{
temp_updateOutputs();
hum_updateOutputs()

Well yes, count your opening and closing braces for 'loop'

Thanks, but I wish it was that easy :slight_smile:
I have 16 "{" and 16 "}"
still no joy.
Thanks anyway.

Yes, but where is the closing brace for 'loop?

Your use of braces is a little eccentric - you have some that are not required, and this may be confusing you.
The trick is to add one to a running count when you encounter an opening brace, and subtracting one when you encounter a closing brace.

The Tools + Auto Format menu item will help you with the random indenting, lining all the code up neatly. The missing/extra curly braces are quite obvious, then.

Thanks for the patients, I must be blind I cant see the problem :~
I agree that I seem to be heavy handed with the braces, but when I start removing them it seems to go from bad to worse.

                              // 0
void loop(void)
 {                            // 1
   if(runTimer == 1) // rum timer once//

  {                           // 2
   timer(); // start timer //
  }                           // 1
   runTimer = 0;
{                            //2
     digitalWrite(timer_relayPin, HIGH);
   }                         //1
 }                           // 0

{                            // 1 OOPS!
  temp_updateOutputs();
  hum_updateOutputs();
  DHT22_ERROR_t errorCode;

If I remove the offending bracket ( // 1 Oops! ), I get the following error. the frustrating part is that all this ran well until I added the timer.
I ran the auto format as suggested - thanks PaulS

etch_oct30a:43: error: expected constructor, destructor, or type conversion before ';' token
sketch_oct30a:44: error: expected constructor, destructor, or type conversion before ';' token
sketch_oct30a:47: error: expected constructor, destructor, or type conversion before '(' token
sketch_oct30a:48: error: expected constructor, destructor, or type conversion before '.' token
sketch_oct30a:49: error: expected constructor, destructor, or type conversion before '=' token
sketch_oct30a:50: error: expected unqualified-id before 'switch'
sketch_oct30a:90: error: expected declaration before '}' token

Time to post your code again.
Use the # icon on the toolbar

Lets look at which braces are necessary.

   if(runTimer == 1) // rum timer once//
  {
   timer(); // start timer //
  }

Necessary? Not strictly, but these are a good idea?

{
     digitalWrite(timer_relayPin, HIGH);
   }

Useless. They make it look like you do not have a clue. Remove them, so maybe you can fool us into thinking that you do.

  switch(errorCode)
  {
    case DHT_ERROR_NONE:
      break;
    case DHT_ERROR_CHECKSUM:
      break;
    case DHT_BUS_HUNG:
      break;
    case DHT_ERROR_NOT_PRESENT:
      break;
    case DHT_ERROR_ACK_TOO_LONG:
      break;
    case DHT_ERROR_SYNC_TIMEOUT:
      break;
    case DHT_ERROR_DATA_TIMEOUT:
      break;
    case DHT_ERROR_TOOQUICK:
      break;
  }

Necessary? Yes.

So, remove all the other braces. They are not in the right places.