Error " 'lcd' was not declared in this scope "

Hello, I have just had the " 'lcd' was not declared in this scope " error message. Can anyone help?
`int HeaterPIN = 11;// Relay for heater
int HumidityPIN = 9; // Humidity PIN
#include <Wire.h>
#include <HDC2080.h>
#include <LiquidCrystal.h>

#define ADDR 0x40
HDC2080 sensor(ADDR);

void setup() {

// For Heater
pinMode(9, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);

sensor.begin();
sensor.reset();
sensor.setMeasurementMode(TEMP_AND_HUMID); // Set measurements to temperature and humidity
sensor.setRate(ONE_HZ); // Set measurement frequency to 1 Hz
sensor.setTempRes(FOURTEEN_BIT);
sensor.setHumidRes(FOURTEEN_BIT);
sensor.triggerMeasurement();

}
void loop() {
delay(100); // delay in between reads for stability

if (sensor.readTemp() < 37.6666) { //37.6666
digitalWrite(HeaterPIN, LOW);

}else if (sensor.readTemp() > 20) { //20
digitalWrite(HeaterPIN, HIGH);

if (sensor.readHumidity() < 51) { //51
digitalWrite(HumidityPIN, HIGH);

}else if (sensor.readHumidity() > 35) { //35
digitalWrite(HumidityPIN, LOW);

}
// LCD module connections (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(7, 6, 10, 8, 3, 2);

char temperature[] = "Temp = 00.0 C";
char humidity[] = "Humidity = 00.0 %";

// set up the LCD's number of columns and rows
lcd.begin(16, 2);

byte Temp = ("Temperature(C): ");
byte (sensor.readTemp());

byte Humid = ("Humidity(%): ");
byte (sensor.readHumidity());
}

/* temperature[7] = Temp / 10 + 48;
temperature[8] = Temp % 10 + 48;
temperature[11] = 223;
humidity[7] = Humidity / 10 + 48;
humidity[8] = Humidity % 10 + 48;
*/
lcd.setCursor(0, 0);
lcd.print("Temp = ");
lcd.setCursor(8, 0);
lcd.print(sensor.readTemp());
lcd.setCursor(14, 0);
lcd.print("C");

lcd.setCursor(0, 1);
lcd.print("Hum = ");
lcd.setCursor(8, 1);
lcd.print(sensor.readHumidity());
lcd.setCursor(14, 1);
lcd.print("%");
}`

Thank you

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Please follow the advice given in the link below when posting code , use code tags and post the code here to make it easier to read and copy for examination

Check your { and your }

Please remember to use code tags when posting code, and post the exact error messages you see

Do you mean at the ones at the beginning and end?

...and all points inbetween

Thanks, I will have a look.

I can't find any problems.

you have code outside of functions.

Try using code tags when you post.

Paste your code after using autoformat.

Three minutes?

Take a longer look.
Use the auro format tool in the IDE

Thanks, Found the problem!

int HeaterPIN = 11;// Relay for heater
int HumidityPIN = 9;     // Humidity PIN
#include <Wire.h>
#include <HDC2080.h>
#include <LiquidCrystal.h>

#define ADDR 0x40
HDC2080 sensor(ADDR);

void setup() {
  pinMode(9, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);

  sensor.begin();
  sensor.reset();
  sensor.setMeasurementMode(TEMP_AND_HUMID);  // Set measurements to temperature and humidity
  sensor.setRate(ONE_HZ);                     // Set measurement frequency to 1 Hz
  sensor.setTempRes(FOURTEEN_BIT);
  sensor.setHumidRes(FOURTEEN_BIT);
  sensor.triggerMeasurement();

}
void loop() {
    delay(100); // delay in between reads for stability
  if (sensor.readTemp() < 37.6666) { //37.6666
    digitalWrite(HeaterPIN, LOW);
  
  }else if (sensor.readTemp() > 20) { //20
    digitalWrite(HeaterPIN, HIGH);
  }
  if (sensor.readHumidity() < 51) { //51
    digitalWrite(HumidityPIN, HIGH);
  
  }else if (sensor.readHumidity() > 35) { //35
    digitalWrite(HumidityPIN, LOW);
  
}
// LCD module connections (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(7, 6, 10, 8, 3, 2);
 
char temperature[] = "Temp = 00.0 C";
char humidity[]    = "Humidity   = 00.0 %";

  // set up the LCD's number of columns and rows
  lcd.begin(16, 2);

  byte Temp = ("Temperature(C): "); 
  byte (sensor.readTemp());

  byte Humid = ("Humidity(%): "); 
  byte (sensor.readHumidity());
  
 
/*  temperature[7]     = Temp / 10 + 48;
  temperature[8]     = Temp % 10 + 48;
  temperature[11]    = 223;
  humidity[7]        = Humidity / 10 + 48;
  humidity[8]        = Humidity % 10 + 48;
  */
  lcd.setCursor(0, 0);
  lcd.print("Temp = ");
  lcd.setCursor(8, 0);
  lcd.print(sensor.readTemp());
  lcd.setCursor(14, 0);
  lcd.print("C");
  
  lcd.setCursor(0, 1);
  lcd.print("Hum  = ");
  lcd.setCursor(8, 1);
  lcd.print(sensor.readHumidity());
  lcd.setCursor(14, 1);
  lcd.print("%");
  }

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.