Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By penatenjoe
#34951 From what I learned the usual libraries cannot cause the issue being discussed. The sensors do provide the data as serial, digitized information. This leaves two sources for error on the side of the µC:

1.) Data corruption: The libraries initate the data transfer by pulling the data pin low and then collect the 5 Byte response. The response contains 2*2 data bytes for temperature and humidity and a 5th byte with the checksum of the 4 data bytes. One has to be aware that the format of the 2 data bytes between DHT11 and DHT22 is different - that is the reason why one has to specify the sensor type. The libraries I have seen flag an error should the checksum not match. If this flag is reading okay the transmitted data is very likely error-free.

2.) Picking the wrong sensor. Unfortunately since the definition of the checksum is the same for both, the DHT11 and DHT22 the adafruit library will not show an error in case the wrong sensor has been selected. The http://playground.arduino.cc/Main/DHTLib will detect if a DHT22 is connected but a DHT11 is declared - but not the other way around. However, since the data format is different the returned humidity / temperature data will be very far off in case the wrong sensor is being used. For example, if one connects a DHT11 at 40% humidity but specifies a DHT22 the reported humidity will be 1024%.