please solve this error message-'lcd' does not name a type

hello I am working on the peoject dht11 with esp01 and aurdino and i want to show temp and humidity value simeltinously on thingspeak and 16x2 LCD diaplay

Error Message -‘lcd’ does not name a type

#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <dht11.h>
#include <DHT.h>
#define RX 2
#define TX 3
#define dht_apin 11 // Analog Pin sensor is connected to
dht11 dhtObject;
String AP = “Redmi”; // AP NAME
String PASS = “Sunny898”; // AP PASSWORD
String API = “XQWPGUVDC8DQDZ97”; // Write API KEY
String HOST = “api.thingspeak.com”;
String PORT = “80”;
int countTrueCommand;
int countTimeCommand;
boolean found = false;
int valSensor = 1;
SoftwareSerial esp8266(RX,TX);
LiquidCrystal lcd(4,5,6,7,8,9);
void setup()
{
Serial.begin(9600);
esp8266.begin(115200);
sendCommand(“AT”,5,“OK”);
sendCommand(“AT+CWMODE=1”,5,“OK”);
sendCommand(“AT+CWJAP=”"+ AP +"",""+ PASS +""",20,“OK”);
lcd.begin(16,2); //16 by 2 character display
}
void loop() {

String getData = “GET /update?api_key=”+ API +"&field1="+getTemperatureValue()+"&field2="+getHumidityValue();
sendCommand(“AT+CIPMUX=1”,5,“OK”);
sendCommand(“AT+CIPSTART=0,“TCP”,”"+ HOST +"","+ PORT,15,“OK”);
sendCommand(“AT+CIPSEND=0,” +String(getData.length()+4),5,">");
esp8266.println(getData);delay(1500);countTrueCommand++;
sendCommand(“AT+CIPCLOSE”,5,“OK”);
}

String getTemperatureValue(){

dhtObject.read(dht_apin);
Serial.print(" Temperature(C)= ");
int temp = dhtObject.temperature;
Serial.println(temp);
delay(50);
return String(temp);

}

String getHumidityValue(){

dhtObject.read(dht_apin);
Serial.print(" Humidity in %= ");
int humidity = dhtObject.humidity;
Serial.println(humidity);
delay(50);
return String(humidity);

}

void sendCommand(String command, int maxTime, char readReplay) {
Serial.print(countTrueCommand);
Serial.print(". at command => “);
Serial.print(command);
Serial.print(” ");
while(countTimeCommand < (maxTime*1))
{
esp8266.println(command);//at+cipsend
if(esp8266.find(readReplay))//ok
{
found = true;
break;
}

countTimeCommand++;
}

if(found == true)
{
Serial.println(“Ok”);
countTrueCommand++;
countTimeCommand = 0;
}

if(found == false)
{
Serial.println(“Fail”);
countTrueCommand = 0;
countTimeCommand = 0;
}

found = false;
}
//DHT11{

// Reading temperature or humidity takes about 250 milliseconds!
float h = dhtObject.read(dht_apin);

float t = dhtObject.read(dht_apin);; // Read temperature as Celsius (the default)

lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(t); //printing temperarture to the LCD display

lcd.print("'C");

lcd.setCursor(0,1);
lcd.print("Humid: ");
lcd.print(h); //printing humidity to the LCD display
lcd.print("%");// error in this line

}

The cause of the error is that you have code outside of any function.

A very helpful troubleshooting tool is the Auto Format feature (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor). If you do an Auto Format and then compare the resulting indentation to your intended program structure, it will quickly point you to where there is a missing or extra brace.

Another useful feature of the Arduino IDE/Arduino Web Editor is that when you place the cursor next to one bracket, it puts a box around the matching bracket. In the Arduino IDE, if the cursor is next to the closing bracket and the opening bracket is off the screen then it will show the opening bracket line in a tool tip after a short delay.Q

It looks like you didn't use 'LCD' as a variable before the void setup command.
Try this:

LiquidCrystal lcd (pin numbers);

void setup(...

#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal.h>
#include <stdlib.h>
#include <DHT.h>
#define DHTPIN A0 // DHT data pin connected to Arduino pin 2
#define DHTTYPE DHT11 // DHT 22 (or AM2302)
#include <dht11.h>
#define RX 2
#define TX 3
#define dht_apin A0 // Analog Pin sensor is connected to
dht11 dhtObject;
String AP = “Redmi”; // AP NAME
String PASS = “Sunny898”; // AP PASSWORD
String API = “ABY09QBF56MZ59QL”; // Write API KEY
String HOST = “api.thingspeak.com”;
String PORT = “80”;
int countTrueCommand;
int countTimeCommand;
boolean found = false;
int valSensor = 1;
SoftwareSerial esp8266(RX,TX);

DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor
float temp;
int hum;
int error;
String tempC;
LiquidCrystal lcd (4,5,6,7,8,9);
void setup()
{
lcd.begin(16, 2);
lcd.print(“MonitoringValues”);
delay(100);
lcd.setCursor(0,1);
lcd.print(“GettingData…”);
Serial.begin(9600);
esp8266.begin(115200);
sendCommand(“AT”,5,“OK”);
sendCommand(“AT+RESTORE”,5,“OK”);
sendCommand(“AT+CWMODE=1”,5,“OK”);
sendCommand(“AT+CWJAP=”"+ AP +"",""+ PASS +""",20,“OK”);
}

void loop()

{
String getData = “GET /update?api_key=”+ API +"&field1="+getTemperatureValue()+"&field2="+getHumidityValue();
sendCommand(“AT+CIPMUX=1”,5,“OK”);
sendCommand(“AT+CIPSTART=0,“TCP”,”"+ HOST +"","+ PORT,15,“OK”);
sendCommand(“AT+CIPSEND=0,” +String(getData.length()+4),4,">");
esp8266.println(getData);delay(1500);countTrueCommand++;
sendCommand(“AT+CIPCLOSE=0”,5,“OK”);
}

String getTemperatureValue(){
dhtObject.read(dht_apin);
Serial.print(" Temperature(C)= ");
int temp = dhtObject.temperature;
Serial.println(temp);
delay(50);
return String(temp);

}
String getHumidityValue(){

dhtObject.read(dht_apin);
Serial.print(" Humidity in %= “);
int humidity = dhtObject.humidity;
Serial.println(humidity);
delay(50);
return String(humidity);
}
void sendCommand(String command, int maxTime, char readReplay)
{
Serial.print(countTrueCommand);
Serial.print(”. at command => “);
Serial.print(command);
Serial.print(” ");
while(countTimeCommand < (maxTime*1))
{
esp8266.println(command);//at+cipsend
if(esp8266.find(readReplay))//ok
{
found = true;
break;
}

countTimeCommand++;
}
if(found == true)
{
Serial.println(“Ok”);
countTrueCommand++;
countTimeCommand = 0;
}
if(found == false)
{
Serial.println(“Fail”);
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}
lcd.clear();
//Read temperature and humidity values from DHT sensor:
start: //label
error=0;
temp = dht.readTemperature();
hum = dht.readHumidity();
lcd.setCursor(0, 0);
lcd.print(“Temp = “);
lcd.print(temp);
lcd.print(” C”);
delay (100);
lcd.setCursor(0, 1); // set the cursor to column 0, line 2
lcd.print(“Humi = “);
lcd.print(hum);
lcd.print(” %”);
delay(1000);
}

Error Message-
Arduino: 1.8.12 (Windows 10), Board: “Arduino Uno”

C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino: In function ‘void setup()’:

C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:39:26: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

sendCommand(“AT”,5,“OK”);

^

C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:40:34: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

sendCommand(“AT+RESTORE”,5,“OK”);

^

C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:41:35: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

sendCommand(“AT+CWMODE=1”,5,“OK”);

^

C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:42:61: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

sendCommand(“AT+CWJAP=”"+ AP +"",""+ PASS +""",20,“OK”);

^

C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino: In function ‘void loop()’:

C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:49:34: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

sendCommand(“AT+CIPMUX=1”,5,“OK”);

^

C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:50:67: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

sendCommand(“AT+CIPSTART=0,“TCP”,”"+ HOST +"","+ PORT,15,“OK”);

^

C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:51:63: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

sendCommand(“AT+CIPSEND=0,” +String(getData.length()+4),4,">");

^

C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:53:36: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]

sendCommand(“AT+CIPCLOSE=0”,5,“OK”);

^

C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino: At global scope:

sketch_mar13b:106:3: error: ‘lcd’ does not name a type

lcd.clear();

^~~

sketch_mar13b:108:8: error: found ‘:’ in nested-name-specifier, expected ‘::’

start: //label

^

sketch_mar13b:108:3: error: ‘start’ does not name a type; did you mean ‘sqrt’?

start: //label

^~~~~

sqrt

sketch_mar13b:110:5: error: ‘temp’ does not name a type

temp = dht.readTemperature();

^~~~

sketch_mar13b:111:5: error: ‘hum’ does not name a type

hum = dht.readHumidity();

^~~

sketch_mar13b:112:5: error: ‘lcd’ does not name a type

lcd.setCursor(0, 0);

^~~

sketch_mar13b:113:5: error: ‘lcd’ does not name a type

lcd.print("Temp = ");

^~~

sketch_mar13b:114:5: error: ‘lcd’ does not name a type

lcd.print(temp);

^~~

sketch_mar13b:115:5: error: ‘lcd’ does not name a type

lcd.print(" C");

^~~

sketch_mar13b:116:11: error: expected constructor, destructor, or type conversion before ‘(’ token

delay (100);

^

sketch_mar13b:117:5: error: ‘lcd’ does not name a type

lcd.setCursor(0, 1); // set the cursor to column 0, line 2

^~~

sketch_mar13b:118:5: error: ‘lcd’ does not name a type

lcd.print("Humi = ");

^~~

sketch_mar13b:119:5: error: ‘lcd’ does not name a type

lcd.print(hum);

^~~

sketch_mar13b:120:5: error: ‘lcd’ does not name a type

lcd.print(" %");

^~~

sketch_mar13b:121:10: error: expected constructor, destructor, or type conversion before ‘(’ token

delay(1000);

^

sketch_mar13b:122:3: error: expected declaration before ‘}’ token

}

^

Multiple libraries were found for “Adafruit_Sensor.h”
Used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\Adafruit_Sensor-master
Not used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\Adafruit_Unified_Sensor
Multiple libraries were found for “SoftwareSerial.h”
Used: C:\Users\Sunny Gaikwad\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\libraries\SoftwareSerial
Not used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\EspSoftwareSerial
Multiple libraries were found for “LiquidCrystal.h”
Used: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
Not used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\NewLiquidCrystal_lib
Multiple libraries were found for “DHT.h”
Used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\DHT-sensor-library-master
Not used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\arduino-DHT-master
Not used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor
Not used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\DHT_sensor_library
exit status 1
‘lcd’ does not name a type

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

I've merged your cross-posts @SunnyGaikwad.

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.