Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By vibhu18
#78668 1. In your code you are missing something. You need to add dht.begin in setup to your code
Code: Select allDHT dht(DHTPIN,DHTTYPE);
unsigned long DHTTimer = 0;
unsigned long DHTInterval = 2000;

void setup{
dht.begin();
}
void loop(){
//normally DHT11 takes around 1-2  sec to get the value so its better to make a delay
if(millis()-DHTTimer>=DHTInterval){
float temp = dht.readTemperature();
float humid = dht.readHumidity();
if(isnan(temp) && isnan(humid)){
return;
}
}
}


2. and one more thing you need to delete pinMode(DHTPIN,INPUT) the function automatically assigns this.

3.if you are using the sensor than add a pull up resistor with a pull up voltage equal to the DHT Vcc and ESP input voltage, In case you are using module then it has internal pull up.