markruys / arduino-DHT

Efficient DHT library for Arduino
Other
162 stars 119 forks source link

Auto Detect (DHT11 vs DHT22) not reliable #13

Open liwenyip opened 6 years ago

liwenyip commented 6 years ago

See below - this is the output I get using the example sketch with a DHT22 connected.

Each blank line indicates when I've pressed the reset button on the Arduino.

NB I'm using a modified version of the example sketch that checks dht.getModel() after dht.setup() is called - see https://github.com/liwenyip/arduino-DHT/commit/ff1c976f1bf2f9145ae9f9738f60f7ed0ec411a7

Auto-detected DHT11
Status  Humidity (%)    Temperature (C) (F)
OK  2.0     1.0     33.8
OK  2.0     1.0     33.8
OK  2.0     1.0     33.8
OK  2.0     1.0     33.8
OK  2.0     1.0     33.8
OK  2.0     1.0     33.8

Auto-detected DHT22
Status  Humidity (%)    Temperature (C) (F)
OK  54.4        27.8        82.0
OK  54.2        27.8        82.0
OK  54.7        27.8        82.0

Auto-detected DHT11
Status  Humidity (%)    Temperature (C) (F)
OK  2.0     1.0     33.8
OK  2.0     1.0     33.8
OK  2.0     1.0     33.8

Auto-detected DHT22
Status  Humidity (%)    Temperature (C) (F)
OK  54.7        27.8        82.0
OK  54.5        27.8        82.0
OK  54.8        27.8        82.0
OK  54.7        27.8        82.0
OK  54.6        27.8        82.0

Auto-detected DHT22
Status  Humidity (%)    Temperature (C) (F)
OK  54.7        27.8        82.0
OK  55.0        27.8        82.0

Auto-detected DHT22
Status  Humidity (%)    Temperature (C) (F)
OK  55.0        27.8        82.0
OK  54.5        27.8        82.0

Auto-detected DHT22
Status  Humidity (%)    Temperature (C) (F)
OK  54.9        27.8        82.0
OK  54.9        27.8        82.0
OK  54.8        27.8        82.0
OK  54.3        27.9        82.2

Auto-detected DHT11
Status  Humidity (%)    Temperature (C) (F)
OK  2.0     1.0     33.8
OK  2.0     1.0     33.8
OK  2.0     1.0     33.8
OK  2.0     1.0     33.8
OK  2.0     1.0     33.8

Auto-detected DHT22
Status  Humidity (%)    Temperature (C) (F)
OK  54.3        27.9        82.2
OK  54.0        28.0        82.4
OK  53.9        28.0        82.4
panigrc commented 5 years ago

I've solved it by hard-coding the sensor type for example:

#define DHT_DATA_PIN 3
#define DHT_TYPE DHT::AM2302

void setup()
{
  dht.setup(DHT_DATA_PIN, DHT_TYPE);
}