-->
Page 2 of 2

Re: Working on Sketch for DHT22 to Pass Sensor Data via MQTT

PostPosted: Thu Aug 09, 2018 10:19 am
by schufti
you spoiled my arc of suspense ... :cry:

Re: Working on Sketch for DHT22 to Pass Sensor Data via MQTT

PostPosted: Wed Oct 17, 2018 2:18 am
by vibhu18
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.