dht11 values returning

hi, i have a loop for reading the dht11 sensor for temperature and humidity.

i tried first the temperature the code below

dht11 DHT11;
DHT11.read(48);
Serial.println(DHT11.temperature);
if (temp>=DHT11.temperature) {digitalWrite(52,LOW);}
else {digitalWrite(52,HIGH);}

where the ''temp'' is a number on eeprom, as a setting to activate a relay

but with this code, the relay is open and closed , always.
i read at println the values below

23297
29
14
23297
28
23297
29
23297
29
23297
29
23297
29
23297

only the ''29'' values are correct, i am wondering what are the others?

after that, i added a delay like this below

dht11 DHT11;
DHT11.read(48);
delay(200);
Serial.println(DHT11.temperature);
if (temp>=DHT11.temperature) {digitalWrite(52,LOW);}
else {digitalWrite(52,HIGH);}

for values of delay, below 200ms, the incoming values are very different .

by adding the delay, i get only the 29 degrees celcius, the correct.

i am wondering , why is this happened?

first learn to post your whole code, the snippets give very little information about possible causes.
(you can attach it too)

When posting code please use code tags == # button above smileys

Finally, the DHT11 needs at least 2000 milliseconds pause between reads, not 200.
That might be the cause.

but with this code, the relay is open and closed , always.

A relay cannot be open and closed at the same time. PLease try to tell the problem as good as you can.
If English is not your mother tongue, write it in your own language and use google translate to help you.

actually, dht11 can be read every 1s (http://www.micro4you.com/files/sensor/DHT11.pdf),
2s is for dht22, but that is definitely what causes bad readings.

you're right, mixed them up :blush: :slight_smile: