Avoid DHT-11 sensors
A few years ago, I realized I had a shoe box with several Raspberry Pi single-board computers just sitting around.
I came across an article saying that interfacing something called a “DHT-11” is a rite of passage for Raspberry Pi users.
Now that I’ve attained Raspberry Pi user status by completing the DHT-11 ordeal, my advice is to use a Bosch BME280 instead. You won’t regret the extra $8-10, and you get temperature, barometric pressure and relative humidity all from one sensor.
Using a Bosch BME180 will get you temperature and barometric pressure, but the library code isn’t as well-developed or easy to use as the BME280 python library.
Both BME180 and BME280 communicate using I2C or SPI protocols, which Raspberry Pis can easily understand.
If you’re only interested in temperature, DS18B20 is more accurate than a DHT-11, and communicates via the standard 1-Wire protocol, rather than the ungainly bit banging a DHT-11 requires.
Don’t bother with a DHT-11, there are better alternative. DHT-11s are worse than mediocre, they’re bad and wrong:
- You have to do some bit banging to get readings. The DHT-11 does not speak a standard protocol like I2C or 1-wire. It’s a pain in the ass, the code to do it is finicky, examples of doing the bit banging are often wrong, and you have to actually use the checksum that reading the DHT-11 provides, because bit banging will hose up sometimes.
- DHT-11 has incomprehensible documentation about what data it returns. Theoretically, a DHT-11 returns 2 bytes of relative humidity, and 2 bytes of temperature. One byte is the “integral part” and one byte is the “decimal part”. What in tarnation does “decimal part” mean? An 8-bit byte can have 256 possible values. Does a “decimal part” byte with a value of “00000001” mean 0.00000001 degrees, or 0.1 degrees? What about a “decimal part” of “111110000”? Is that 0.240 degrees or 0.8571 degrees, or something else? All DHT-11 data sheets repeat this gibberish.
- DHT-11s have a nominal temperature sensing range of 0-50C, with an accuracy of ± 2C. That’s just too coarse to be of any use.
- When ambient temperature is below 0C, whackiness ensues. I had two thermometers on a Raspberry Pi in my garage, winter of 2022, a DHT-11 and a DS18B20. During a cold snap in February of 2022, temperatures in my garage fell below freezing. The DHT-11 designers stuck strictly to their spec range of 0-50C, stripping off the sign bit of the temperature, but failed to clamp the value to 0C. Notice the DHT-11 temperature rising during Feb 3, 2022. The DHT-11 gives a positive reading of roughly the negative reading of the DS18B20. By strictly following the spec, the designers of this particular DHT-11 made something that’s not just mediocre, but outright wrong.