Help with adding a variable to 'else, if' statements please

I have been trying for a while but can't get the array working. When I replace the old with the new code in your post I get errors on the next bit of code stating all the averages, average4.. were not declared in this scope? Not sure how I declare them?

When I replace the old with the new code in your post I get errors on the next bit of code stating all the averages, average4.. were not declared in this scope? Not sure how I declare them?

Show us the code and the errors.

PaulS:

I have looked at arrays before in brief detail but I not sure how this could be changed into one?

float average = 0;                     //input1

float average1 = 0;                    //input2
  float average2 = 0;                    //input3
  float average3 = 0;                    //input4
  float average4 = 0;                    //input5
  float average5 = 0;                    //input6



becomes


float average[6];
  for(int i=0; i<6; i++)
  {
    average[i] /= NUMSAMPLES;
  }

Having looked over dtokez code more I think what Paul suggested is a good idea but doesn't match exactly what dtokez code is doing so it is not a drop-in replacement for what dtokez had to begin with, thus my modification of Paul's code won't work for dtokez directly either.

I'll add, that's why a lot of people like to do:

  if(0 == desired && hallTemp <setPoint - hysteresis)

Because if you forget the second '=', you wind up with an assignment to a literal rather than a variable, which the compiler will catch. Thusly, completely avoiding the problem in the first place.

Ok, I'm a bit lost with that one so I will leave that for now - it works so at least I can improve it later. I have now had another idea, I would like to loop the section of code that reads the pot input and updates the LCD, because at the moment the LCD will only refresh once the entire program has run - I don't need to update the temperatures that often.

I thought maybe I could use a for loop, and a counter that will loop the bit of code I just talked about through x amount of times, then run the rest of my code to the end

How would I go about doing this? I have only found examples in which a delay inside the for loop is used, or a variety that waits forever for an event before it moves on?

Thanks!

Forgot to post the code that I am currently working with - it is a little cleaner now

/*
 The circuit:
 * LDR connected to analog pin 0.
 * LED / transistor connected from digital pin 3 to ground
 
 * LCD RS pin to digital pin 7
 * LCD EN pin to digital pin 8
 * LCD D4 pin to digital pin 9
 * LCD D5 pin to digital pin 10
 * LCD D6 pin to digital pin 11
 * LCD D7 pin to digital pin 12
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 * LCD LED+ (15) pin transistor
 * LCD LED- (16) to ground 
 
 * Thermisor divider 1 output to analog pin 1
 * Thermisor divider 2 output to analog pin 2
 */

// These constants won't change.  They're used to give names
// to the pins used:
const int tempSelectPot = A0;      // Analog input pin that the temp select pot is attached to
const int LDRPin = A1;      // Analog input pin that the lDR is attached to
const int LCDBackLight = 3;      // Analog (PWM) output pin that the BACKLIGHT is attached to
const int coldPin = 2;      // Digital output pin that the COLD RELAY is attached to
const int frostPin = 4;      // Digital output pin that the frost warning LED is attached to
//const int hotPin = 5;      // Digital output pin that the HOT LED is attached to
const int out = A2;         // Analog input that the 'Out' thermistor is connected too
const int hall = A3;         // Analog input that the 'Hall' thermistor is connected too
const int bed = A4;         // Analog input that the 'Bed' thermistor is connected too
const int bath = A5;         // Analog input that the 'Bath' thermistor is connected too
const int lounge = A6;         // Analog input that the 'Lounge' thermistor is connected too
const int kitchen = A7;         // Analog input that the 'Kitchen' thermistor is connected too
const int modeButton = 6;      //Digital input that the mode button is connected too

//floating point values
float averageTemp = 0;         //place to store average reading
float desired = 0;         //place to store selected mode 

//Parameters**************

//const int hotTemp = 20;       // upper do something threshold in degrees c
const int setPointLow = 5;    // lowest desired temp available to select in degrees c
const int setPointHigh = 25;  // highest desired temp available to select in degrees c
const int frostWarning = 5;  // outside frost warning LED on threshold in degrees c
float hysteresis = 0.4;       // Temperature error switching margin to avoid rapid activation in degrees c

const int minLight = 80;        // at or below this light level, use minimum backlight intensity
const int maxLight = 920;        // at or above this light level, use maximum backlight intensity
const int minBacklight = 10;      // lowest backlight intensity to use
const int maxBacklight = 255;    // highest backlight intensity to use

// include the library code:
#include <LiquidCrystal.h>
#include <math.h>

#define NUMSAMPLES 32 // Number of analog samples to take


double convert(double RawADC) 
{
  double Temp;
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
  Temp = Temp - 273.15;            // Convert Kelvin to Celcius

  return Temp;
}

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int potRead = 0;         // value read from the pot
int LDRRead = 0;         // value read from the LDR
int outputValue = 0;     // value output to the PWM (analog out)
int setPoint = 0;        // value set point



void setup() 
{
  lcd.begin(20, 4);
  delay(100);
  
  //Declare pin modes 
  pinMode(3, OUTPUT);   //LCD BACKLIGHT
  pinMode(coldPin, OUTPUT);   //COLD WARNING
  pinMode(frostPin, OUTPUT);   //OUTSIDE FROST WARNING
  pinMode(modeButton, INPUT);   //MODE SELECT BUTTON
  digitalWrite(modeButton, HIGH); //set input button to 5v to use internal pull up
}

void loop() 
{
  // LDR controlled LCD backlight via PWM part
  int sum = 0;
  for (int i=0; i<16; i++) // take 16 samples from the analog input
  {
    sum += analogRead(LDRPin);
  }
  LDRRead = sum/16; // divide by the amount of samples for the average value

  // map it to the range[0..255] of the analog output that the LCD backlight it connected to
  outputValue = LDRRead/4;   // alternative to map function for scaling down from analog input
  outputValue = map(constrain(LDRRead, minLight, maxLight), minLight, maxLight, minBacklight, maxBacklight );

  // change the analog out value to adjust LCD backlight intensity
  analogWrite(LCDBackLight, outputValue);           


  // Desired temperature selection via potentiometer part
  potRead = analogRead(tempSelectPot);
  setPoint = map (potRead, 0, 1023, setPointLow, setPointHigh);


  // Temperature measurement and averaging part
  uint8_t i;
  float average1 = 0;                     //input1
  float average2 = 0;                    //input2
  float average3 = 0;                    //input3
  float average4 = 0;                    //input4
  float average5 = 0;                    //input5
  float average6 = 0;                    //input6
  for (i=0; i< NUMSAMPLES; i++)             
  {
    average1 += analogRead(out);
    average2 += analogRead(hall);
    average3 += analogRead(bed);
    average4 += analogRead(bath);
    average5 += analogRead(lounge);
    average6 += analogRead(kitchen);
    delay(10);
  }
  average1 /= NUMSAMPLES;
  average2 /= NUMSAMPLES;
  average3 /= NUMSAMPLES;
  average4 /= NUMSAMPLES;
  average5 /= NUMSAMPLES;
  average6 /= NUMSAMPLES;

  double outTemp = convert(average1);
  double hallTemp = convert(average2);
  double bedTemp = convert(average3);
  double bathTemp = convert(average4);
  double loungeTemp = convert(average5);
  double kitchenTemp = convert(average6);

//Clear the LCD ready for fresh data to be printed
  lcd.clear(); 


  //THERMOSTAT DUTIES
  desired = digitalRead(modeButton);

  if(desired == HIGH && hallTemp <setPoint - hysteresis)
  {
    digitalWrite(coldPin, HIGH);   // set the LED on
    lcd.setCursor(19,4);
    lcd.print((char)165); // print symbol for local temp selection
  }
  else if (desired == HIGH && hallTemp >setPoint + hysteresis)
  {
    digitalWrite(coldPin, LOW);   // set the LED off
    lcd.setCursor(19,4);
    lcd.print((char)165);         // print symbol for local temp selection
  }
  else if (desired == LOW && averageTemp <setPoint + hysteresis)
  {
    digitalWrite(coldPin, HIGH);   // set the LED off
    lcd.setCursor(19,4);
    lcd.print((char)219);         // print symbol for average temp selection
  }
  else if (desired == LOW && averageTemp >setPoint + hysteresis){
    digitalWrite(coldPin, LOW);   // set the LED off
    lcd.setCursor(19,4);
    lcd.print((char)219);        // print symbol for average temp selection
  }


  //Print desired set point temp to LCD
  lcd.setCursor(11,4);
  lcd.print ("Set: ");

  if(setPoint <setPointLow +1)
    lcd.print((char)42);              // print symbol for frost protection setting
  else if (setPoint >setPointLow)
    lcd.print(setPoint);


  //Print average temp to LCD   
  averageTemp = hallTemp + bedTemp + bathTemp + loungeTemp + kitchenTemp;         // temp zones to take average from
  averageTemp = averageTemp/5;                                                    // divide by number of temp zones to get average

  lcd.setCursor(11,2);
  lcd.print ("Ave: ");
  lcd.print(averageTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");
    
//Print hall temp to LCD
  lcd.setCursor(0,0);
  lcd.print ("Hal: ");
  lcd.print(hallTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print lounge temp to LCD
  lcd.setCursor(11,0);
  lcd.print ("Lng: ");
  lcd.print(loungeTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print kitchen temp to LCD
  lcd.setCursor(0,1);
  lcd.print ("Kit: ");
  lcd.print(kitchenTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print bedroom temp to LCD
  lcd.setCursor(11,1);
  lcd.print ("Bed: ");
  lcd.print(bedTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print bathroom temp to LCD
  lcd.setCursor(0,2);
  lcd.print ("Bth: ");
  lcd.print(bathTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print outside temp to LCD
  lcd.setCursor(0,4);
  lcd.print ("Out: ");
  lcd.print(outTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");


// Exterior frost warning LED part
  if(outTemp <frostWarning - hysteresis)
    digitalWrite(frostPin, HIGH);                    // set the LED on
  else if (outTemp >frostWarning + hysteresis)
    digitalWrite(frostPin, LOW);                     // set the LED off
    
    

  delay(1000);                     
}
float average1 = 0;                     //input1
  float average2 = 0;                    //input2
  float average3 = 0;                    //input3
  float average4 = 0;                    //input4
  float average5 = 0;                    //input5
  float average6 = 0;                    //input6
  for (i=0; i< NUMSAMPLES; i++)             
  {
    average1 += analogRead(out);
    average2 += analogRead(hall);
    average3 += analogRead(bed);
    average4 += analogRead(bath);
    average5 += analogRead(lounge);
    average6 += analogRead(kitchen);
    delay(10);
  }
  average1 /= NUMSAMPLES;
  average2 /= NUMSAMPLES;
  average3 /= NUMSAMPLES;
  average4 /= NUMSAMPLES;
  average5 /= NUMSAMPLES;
  average6 /= NUMSAMPLES;

  double outTemp = convert(average1);
  double hallTemp = convert(average2);
  double bedTemp = convert(average3);
  double bathTemp = convert(average4);
  double loungeTemp = convert(average5);
  double kitchenTemp = convert(average6);

This just screams "array and for loop"

AWOL:
This just screams "array and for loop"

I know I was trying for most of the day Sunday but could not get anything that would compile let alone work :frowning:

Anyone care to advise?

Thanks

Anyone care to advise?

Same advice I always give. Show what you have tried, and describe the problems/show the error messages.

const int sensorPins [] = {out, hall, bed, bath, lounge, kitchen};

I'm really confused with this. Where do I reference to 'sensorPins'?

I don't understand how to implement this into an array, I have just messed it up again :frowning:

  // Temperature measurement and averaging part
  uint8_t i;
  float average1 = 0;                    //input1
  float average2 = 0;                    //input2
  float average3 = 0;                    //input3
  float average4 = 0;                    //input4
  float average5 = 0;                    //input5
  float average6 = 0;                    //input6
  
  
  for (i=0; i< NUMSAMPLES; i++)             
  {
    average1 += analogRead(out);
    average2 += analogRead(hall);
    average3 += analogRead(bed);
    average4 += analogRead(bath);
    average5 += analogRead(lounge);
    average6 += analogRead(kitchen);
    delay(10);
  }
  
  
  
  for (i=0; i< 6; I++)
  {
  average1 /= NUMSAMPLES;
  average2 /= NUMSAMPLES;
  average3 /= NUMSAMPLES;
  average4 /= NUMSAMPLES;
  average5 /= NUMSAMPLES;
  average6 /= NUMSAMPLES;
}

  double outTemp = convert(average1);
  double hallTemp = convert(average2);
  double bedTemp = convert(average3);
  double bathTemp = convert(average4);
  double loungeTemp = convert(average5);
  double kitchenTemp = convert(average6);
for (i=0; i< NUMSAMPLES; i++) {
   for (j = 0; j < sizeof (sensorPins) / sizeof (sensorPins [0]); j++)
    average[j] += analogRead(sensorPins[j]);
   }
}

If you wish, you can transpose the for loops, but this affects the order in which you sample the pins

Ah right, thanks Awol - I can follow some of that I think.
Would this be the order in which they read? const int sensorPins [] = {out, hall, bed, bath, lounge, kitchen};

And I would have to declare the 'sizeof' the array?

how would I then pull the value that has been averaged to be used elsewhere in the program?

Thanks for the help :slight_smile:

Would this be the order in which they read?

Yes.

And I would have to declare the 'sizeof' the array?

No. sizeof() is a function that returns that size of whatever is in the parentheses. In this case, it is determining how many bytes the array occupies, then dividing that by the size of one element of the array, to determine the number of elements in the array (so you don't have to).

trying to make it work with the array tonight. No success sadly.

I am getting lots of errors on compile.

/*
 The circuit:
 * LDR connected to analog pin 0.
 * LED / transistor connected from digital pin 3 to ground
 
 * LCD RS pin to digital pin 7
 * LCD EN pin to digital pin 8
 * LCD D4 pin to digital pin 9
 * LCD D5 pin to digital pin 10
 * LCD D6 pin to digital pin 11
 * LCD D7 pin to digital pin 12
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 * LCD LED+ (15) pin transistor
 * LCD LED- (16) to ground 
 
 * Thermisor divider 1 output to analog pin 1
 * Thermisor divider 2 output to analog pin 2
 */

// These constants won't change.  They're used to give names
// to the pins used:
const int tempSelectPot = A0;      // Analog input pin that the temp select pot is attached to
const int LDRPin = A1;      // Analog input pin that the lDR is attached to
const int LCDBackLight = 3;      // Analog (PWM) output pin that the BACKLIGHT is attached to
const int coldPin = 2;      // Digital output pin that the COLD RELAY is attached to
const int frostPin = 4;      // Digital output pin that the frost warning is attached to
//const int hotPin = 5;      // Digital output pin that the HOT LED is attached to
const int out = A2;         // Analog input that the 'Out' thermistor is connected too
const int hall = A3;         // Analog input that the 'Hall' thermistor is connected too
const int bed = A4;         // Analog input that the 'Bed' thermistor is connected too
const int bath = A5;         // Analog input that the 'Bath' thermistor is connected too
const int lounge = A6;         // Analog input that the 'Lounge' thermistor is connected too
const int kitchen = A7;         // Analog input that the 'Kitchen' thermistor is connected too
const int modeButton = 6;      //Digital input that the mode button is connected too

const int sensorPins [] = {out, hall, bed, bath, lounge, kitchen};


//floating point values
float averageTemp = 0;         //place to store average reading
float desired = 0;         //place to store selected mode 

//Parameters**************

//const int hotTemp = 20;       // upper do something threshold in degrees c
const int setPointLow = 5;    // lowest desired temp available to select in degrees c
const int setPointHigh = 25;  // highest desired temp available to select in degrees c
const int frostWarning = 5;  // outside frost warning LED on threshold in degrees c
float hysteresis = 0.4;       // Temperature error switching margin to avoid rapid activation in degrees c

const int minLight = 80;        // at or below this light level, use minimum backlight intensity
const int maxLight = 920;        // at or above this light level, use maximum backlight intensity
const int minBacklight = 10;      // lowest backlight intensity to use
const int maxBacklight = 255;    // highest backlight intensity to use

// include the library code:
#include <LiquidCrystal.h>
#include <math.h>

#define NUMSAMPLES 32 // Number of analog samples to take


double convert(double RawADC) 
{
  double Temp;
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
  Temp = Temp - 273.15;            // Convert Kelvin to Celcius

  return Temp;
}

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int potRead = 0;         // value read from the pot
int LDRRead = 0;         // value read from the LDR
int outputValue = 0;     // value output to the PWM (analog out)
int setPoint = 0;        // value set point



void setup() 
{
  lcd.begin(20, 4);
  delay(100);
  
  //Declare pin modes 
  pinMode(3, OUTPUT);   //LCD BACKLIGHT
  pinMode(coldPin, OUTPUT);   //COLD WARNING
  pinMode(frostPin, OUTPUT);   //OUTSIDE FROST WARNING
  pinMode(modeButton, INPUT);   //MODE SELECT BUTTON
  digitalWrite(modeButton, HIGH); //set input button to 5v to use internal pull up
}

void loop() 
{
  // LDR controlled LCD backlight via PWM part
  int sum = 0;
  for (int i=0; i<16; i++) // take 16 samples from the analog input
  {
    sum += analogRead(LDRPin);
  }
  LDRRead = sum/16; // divide by the amount of samples for the average value

  // map it to the range[0..255] of the analog output that the LCD backlight it connected to
  outputValue = LDRRead/4;   // alternative to map function for scaling down from analog input
  outputValue = map(constrain(LDRRead, minLight, maxLight), minLight, maxLight, minBacklight, maxBacklight );

  // change the analog out value to adjust LCD backlight intensity
  analogWrite(LCDBackLight, outputValue);           


  // Desired temperature selection via potentiometer part
  potRead = analogRead(tempSelectPot);
  setPoint = map (potRead, 0, 1023, setPointLow, setPointHigh);


  // Temperature measurement and averaging part
  uint8_t i;
  float average1 = 0;                     //input1
  float average2 = 0;                    //input2
  float average3 = 0;                    //input3
  float average4 = 0;                    //input4
  float average5 = 0;                    //input5
  float average6 = 0;                    //input6
  
for (i=0; i< NUMSAMPLES; i++) {
   for (j = 0; j < sizeof (sensorPins) / sizeof (sensorPins [0]); j++)
    average[j] += analogRead(sensorPins[j]);
   }
}

  double outTemp = convert(average1);
  double hallTemp = convert(average2);
  double bedTemp = convert(average3);
  double bathTemp = convert(average4);
  double loungeTemp = convert(average5);
  double kitchenTemp = convert(average6);




  //THERMOSTAT DUTIES
  digitalRead(modeButton);
  delay(100);                          //some bebounce time
  desired = digitalRead(modeButton);
  
  //Clear the LCD ready for fresh data to be printed
  lcd.clear(); 

  if(desired == HIGH)              
{
  lcd.setCursor(19,4);
  lcd.print((char)165);
}
else if(desired == LOW)
{
  lcd.setCursor(19,4);
    lcd.print((char)219);
}

  
  
  

  if(desired == HIGH && hallTemp <setPoint - hysteresis)
  {
    digitalWrite(coldPin, HIGH);   // set the LED on
  }
  else if (desired == HIGH && hallTemp >setPoint + hysteresis)
  {
    digitalWrite(coldPin, LOW);   // set the LED off
  }
  else if (desired == LOW && averageTemp <setPoint + hysteresis)
  {
    digitalWrite(coldPin, HIGH);   // set the LED off
  }
  else if (desired == LOW && averageTemp >setPoint + hysteresis)
  {
    digitalWrite(coldPin, LOW);   // set the LED off
  }


  //Print desired set point temp to LCD
  lcd.setCursor(11,4);
  lcd.print ("Set: ");

  if(setPoint <setPointLow +1)
    lcd.print((char)42);              // print symbol for frost protection setting
  else if (setPoint >setPointLow)
    lcd.print(setPoint);


  //Print average temp to LCD   
  averageTemp = hallTemp + bedTemp + bathTemp + loungeTemp + kitchenTemp;         // temp zones to take average from
  averageTemp = averageTemp/5;                                                    // divide by number of temp zones to get average

  lcd.setCursor(11,2);
  lcd.print ("Ave: ");
  lcd.print(averageTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");
    
//Print hall temp to LCD
  lcd.setCursor(0,0);
  lcd.print ("Hal: ");
  lcd.print(hallTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print lounge temp to LCD
  lcd.setCursor(11,0);
  lcd.print ("Lng: ");
  lcd.print(loungeTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print kitchen temp to LCD
  lcd.setCursor(0,1);
  lcd.print ("Kit: ");
  lcd.print(kitchenTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print bedroom temp to LCD
  lcd.setCursor(11,1);
  lcd.print ("Bed: ");
  lcd.print(bedTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print bathroom temp to LCD
  lcd.setCursor(0,2);
  lcd.print ("Bth: ");
  lcd.print(bathTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print outside temp to LCD
  lcd.setCursor(0,4);
  lcd.print ("Out: ");
  lcd.print(outTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");


// Exterior frost warning LED part
  if(outTemp <frostWarning - hysteresis)
    digitalWrite(frostPin, HIGH);                    // set the LED on
  else if (outTemp >frostWarning + hysteresis)
    digitalWrite(frostPin, LOW);                     // set the LED off
    
    

  delay(900);                     
}

errors

Thermostat_Release_1_0.cpp: In function 'void loop()':
Thermostat_Release_1_0:131: error: 'j' was not declared in this scope
Thermostat_Release_1_0:132: error: 'average' was not declared in this scope
Thermostat_Release_1_0.cpp: At global scope:
Thermostat_Release_1_0:136: error: 'average1' was not declared in this scope
Thermostat_Release_1_0:137: error: 'average2' was not declared in this scope
Thermostat_Release_1_0:138: error: 'average3' was not declared in this scope
Thermostat_Release_1_0:139: error: 'average4' was not declared in this scope
Thermostat_Release_1_0:140: error: 'average5' was not declared in this scope
Thermostat_Release_1_0:141: error: 'average6' was not declared in this scope
Thermostat_Release_1_0:147: error: expected constructor, destructor, or type conversion before '(' token
Thermostat_Release_1_0:148: error: expected constructor, destructor, or type conversion before '(' token
Thermostat_Release_1_0:149: error: expected constructor, destructor, or type conversion before '=' token
Thermostat_Release_1_0:152: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:154: error: expected unqualified-id before 'if'
Thermostat_Release_1_0:159: error: expected unqualified-id before 'else'
Thermostat_Release_1_0:169: error: expected unqualified-id before 'if'
Thermostat_Release_1_0:173: error: expected unqualified-id before 'else'
Thermostat_Release_1_0:177: error: expected unqualified-id before 'else'
Thermostat_Release_1_0:181: error: expected unqualified-id before 'else'
Thermostat_Release_1_0:188: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:189: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:191: error: expected unqualified-id before 'if'
Thermostat_Release_1_0:193: error: expected unqualified-id before 'else'
Thermostat_Release_1_0:198: error: expected constructor, destructor, or type conversion before '=' token
Thermostat_Release_1_0:199: error: expected constructor, destructor, or type conversion before '=' token
Thermostat_Release_1_0:201: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:202: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:203: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:208: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:209: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:210: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:215: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:216: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:217: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:222: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:223: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:224: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:229: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:230: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:231: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:236: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:237: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:238: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:243: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:244: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:245: error: expected constructor, destructor, or type conversion before '.' token
Thermostat_Release_1_0:251: error: expected unqualified-id before 'if'
Thermostat_Release_1_0:253: error: expected unqualified-id before 'else'
Thermostat_Release_1_0:258: error: expected constructor, destructor, or type conversion before '(' token
Thermostat_Release_1_0:259: error: expected declaration before '}' token

Too many RH braces here, for a start:

for (i=0; i< NUMSAMPLES; i++) {
   for (j = 0; j < sizeof (sensorPins) / sizeof (sensorPins [0]); j++)
    average[j] += analogRead(sensorPins[j]);
   }
}

What AWOL means is to change:

  float average1 = 0;                     //input1
  float average2 = 0;                    //input2
  float average3 = 0;                    //input3
  float average4 = 0;                    //input4
  float average5 = 0;                    //input5
  float average6 = 0;                    //input6

to:

  float average [6] = 0;

Then the loop will iterate over all 6 averages (numbered 0 to 5);

Thanks Nick, I have just tried to implement those changes but still getting multiple compile errors :frowning:

Not quite sure where i'm going wrong, confused as to why i'm getting errors about things not being declared?

/*
 The circuit:
 * LDR connected to analog pin 0.
 * LED / transistor connected from digital pin 3 to ground
 
 * LCD RS pin to digital pin 7
 * LCD EN pin to digital pin 8
 * LCD D4 pin to digital pin 9
 * LCD D5 pin to digital pin 10
 * LCD D6 pin to digital pin 11
 * LCD D7 pin to digital pin 12
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 * LCD LED+ (15) pin transistor
 * LCD LED- (16) to ground 
 
 * Thermisor divider 1 output to analog pin 1
 * Thermisor divider 2 output to analog pin 2
 */

// These constants won't change.  They're used to give names
// to the pins used:
const int tempSelectPot = A0;      // Analog input pin that the temp select pot is attached to
const int LDRPin = A1;      // Analog input pin that the lDR is attached to
const int LCDBackLight = 3;      // Analog (PWM) output pin that the BACKLIGHT is attached to
const int coldPin = 2;      // Digital output pin that the COLD RELAY is attached to
const int frostPin = 4;      // Digital output pin that the frost warning is attached to
//const int hotPin = 5;      // Digital output pin that the HOT LED is attached to
const int out = A2;         // Analog input that the 'Out' thermistor is connected too
const int hall = A3;         // Analog input that the 'Hall' thermistor is connected too
const int bed = A4;         // Analog input that the 'Bed' thermistor is connected too
const int bath = A5;         // Analog input that the 'Bath' thermistor is connected too
const int lounge = A6;         // Analog input that the 'Lounge' thermistor is connected too
const int kitchen = A7;         // Analog input that the 'Kitchen' thermistor is connected too
const int modeButton = 6;      //Digital input that the mode button is connected too

const int sensorPins [] = {out, hall, bed, bath, lounge, kitchen};


//floating point values
float averageTemp = 0;         //place to store average reading
float desired = 0;         //place to store selected mode 

//Parameters**************

//const int hotTemp = 20;       // upper do something threshold in degrees c
const int setPointLow = 5;    // lowest desired temp available to select in degrees c
const int setPointHigh = 25;  // highest desired temp available to select in degrees c
const int frostWarning = 5;  // outside frost warning LED on threshold in degrees c
float hysteresis = 0.4;       // Temperature error switching margin to avoid rapid activation in degrees c


const int minLight = 80;        // at or below this light level, use minimum backlight intensity
const int maxLight = 920;        // at or above this light level, use maximum backlight intensity
const int minBacklight = 10;      // lowest backlight intensity to use
const int maxBacklight = 255;    // highest backlight intensity to use

// include the library code:
#include <LiquidCrystal.h>
#include <math.h>

#define NUMSAMPLES 32 // Number of analog samples to take


double convert(double RawADC) 
{
  double Temp;
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
  Temp = Temp - 273.15;            // Convert Kelvin to Celcius

  return Temp;
}

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int potRead = 0;         // value read from the pot
int LDRRead = 0;         // value read from the LDR
int outputValue = 0;     // value output to the PWM (analog out)
int setPoint = 0;        // value set point



void setup() 
{
  lcd.begin(20, 4);
  delay(100);
  
  //Declare pin modes 
  pinMode(3, OUTPUT);   //LCD BACKLIGHT
  pinMode(coldPin, OUTPUT);   //COLD WARNING
  pinMode(frostPin, OUTPUT);   //OUTSIDE FROST WARNING
  pinMode(modeButton, INPUT);   //MODE SELECT BUTTON
  digitalWrite(modeButton, HIGH); //set input button to 5v to use internal pull up
}

void loop() 
{
  // LDR controlled LCD backlight via PWM part
  int sum = 0;
  for (int i=0; i<16; i++) // take 16 samples from the analog input
  {
    sum += analogRead(LDRPin);
  }
  LDRRead = sum/16; // divide by the amount of samples for the average value

  // map it to the range[0..255] of the analog output that the LCD backlight it connected to
  outputValue = LDRRead/4;   // alternative to map function for scaling down from analog input
  outputValue = map(constrain(LDRRead, minLight, maxLight), minLight, maxLight, minBacklight, maxBacklight );

  // change the analog out value to adjust LCD backlight intensity
  analogWrite(LCDBackLight, outputValue);           


  // Desired temperature selection via potentiometer part
  potRead = analogRead(tempSelectPot);
  setPoint = map (potRead, 0, 1023, setPointLow, setPointHigh);


  // Temperature measurement and averaging part

  
for (i=0; i< NUMSAMPLES; i++) {
   for (j = 0; j < sizeof (sensorPins) / sizeof (sensorPins [0]); j++)
    average[j] += analogRead(sensorPins[j]);
   }
   
  float average [6] = 0;

  double outTemp = convert(average0);
  double hallTemp = convert(average1);
  double bedTemp = convert(average2);
  double bathTemp = convert(average3);
  double loungeTemp = convert(average4);
  double kitchenTemp = convert(average5);




  //THERMOSTAT DUTIES
  digitalRead(modeButton);
  delay(100);                          //some bebounce time
  desired = digitalRead(modeButton);
  
  //Clear the LCD ready for fresh data to be printed
  lcd.clear(); 

  if(desired == HIGH)              
{
  lcd.setCursor(19,4);
  lcd.print((char)165);
}
else if(desired == LOW)
{
  lcd.setCursor(19,4);
    lcd.print((char)219);
}

  
  
  

  if(desired == HIGH && hallTemp <setPoint - hysteresis)
  {
    digitalWrite(coldPin, HIGH);   // set the LED on
  }
  else if (desired == HIGH && hallTemp >setPoint + hysteresis)
  {
    digitalWrite(coldPin, LOW);   // set the LED off
  }
  else if (desired == LOW && averageTemp <setPoint + hysteresis)
  {
    digitalWrite(coldPin, HIGH);   // set the LED off
  }
  else if (desired == LOW && averageTemp >setPoint + hysteresis)
  {
    digitalWrite(coldPin, LOW);   // set the LED off
  }


  //Print desired set point temp to LCD
  lcd.setCursor(11,4);
  lcd.print ("Set: ");

  if(setPoint <setPointLow +1)
    lcd.print((char)42);              // print symbol for frost protection setting
  else if (setPoint >setPointLow)
    lcd.print(setPoint);


  //Print average temp to LCD   
  averageTemp = hallTemp + bedTemp + bathTemp + loungeTemp + kitchenTemp;         // temp zones to take average from
  averageTemp = averageTemp/5;                                                    // divide by number of temp zones to get average

  lcd.setCursor(11,2);
  lcd.print ("Ave: ");
  lcd.print(averageTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");
    
//Print hall temp to LCD
  lcd.setCursor(0,0);
  lcd.print ("Hal: ");
  lcd.print(hallTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print lounge temp to LCD
  lcd.setCursor(11,0);
  lcd.print ("Lng: ");
  lcd.print(loungeTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print kitchen temp to LCD
  lcd.setCursor(0,1);
  lcd.print ("Kit: ");
  lcd.print(kitchenTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print bedroom temp to LCD
  lcd.setCursor(11,1);
  lcd.print ("Bed: ");
  lcd.print(bedTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print bathroom temp to LCD
  lcd.setCursor(0,2);
  lcd.print ("Bth: ");
  lcd.print(bathTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");

  //Print outside temp to LCD
  lcd.setCursor(0,4);
  lcd.print ("Out: ");
  lcd.print(outTemp, 1);
  //lcd.print((char)223);
  //lcd.print ("c");


// Exterior frost warning LED part
  if(outTemp <frostWarning - hysteresis)
    digitalWrite(frostPin, HIGH);                    // set the LED on
  else if (outTemp >frostWarning + hysteresis)
    digitalWrite(frostPin, LOW);                     // set the LED off
    
    

  delay(900);                     
}

It'd help if you had a variables named 'i' and 'j' or better yet do it this way!

for ( int i = 0; i < NUMSAMPLES; i++ )
{
	for ( int j = 0; j < sizeof(sensorPins) / sizeof(sensorPins[0]); j++ )
	{
		average[j] += analogRead(sensorPins[j]);
	}
}

Code formatting, including brace placement, can make it easier to spot problems.