RobTillaart / DHTstable

Arduino Library for the DHT temperature and humidity sensor.
MIT License
17 stars 4 forks source link

DHT22 temperature is 1ºC smaller than DHT11 #7

Closed afonsoc12 closed 3 years ago

afonsoc12 commented 3 years ago

Hi,

I have been testing this library with a DHT11 and a DHT22, since I could not make Adafruit's one work with DHT22 sensor (it stops working after 2h of usage).

Anyway, this library is working great, but the readings of the DHT22 are consistently 1ºC smaller than DHT11. My setup is a couple of ESP01s, (one for each sensor), 5K pull-ups and small cables (so that the pullups are reasonable in this setup).

Living Room - DHT22 Kitchen -DHT11

Note that despite the names, they are side-by-side in a breadboard, while I am testing its stability. For comparison, I can tell you that Echo has a room temperature of 17.8ºC degrees, making the DHT11 the more reliable (within the upper 5% error margin).

image

Any thought on why this is happening? Does changing to DHTnew solve this?

Thanks

RobTillaart commented 3 years ago

Good question, The reason is (in my experiences) that the DHT22 sensors are pretty precise not too accurate.

Precise = multiple readings give the same value Accuracy = readings give correct value.

The datasheet describes a process to recalibrate, however i never did not do that myself. Expectation is that it will affect primarily the humidity..

RobTillaart commented 3 years ago

Dhtnew has functions to correct T and H with a linear offset. This reduces he problem especially if the error is nearly constant over your operational range.

If the accuracy error is not constant, you might take a look at my multimap function.

Another solution is to switch to an other sensor e.g. SHT35 or SHT85 but these are (more) expensive.

RobTillaart commented 3 years ago

Multimap => https://github.com/RobTillaart/MultiMap precision and accuracy (picture show difference) => https://wp.stolaf.edu/it/gis-precision-accuracy/

afonsoc12 commented 3 years ago

Hi, Thanks for looking into this.

DHT22 is definitely more precise than DHT11, and it seems that the measurements are a solid 1ºC smaller.

About multimap, it could be a good solution, but I don't have a solid range of values for it to compute the interpolations, i.e., temperatures may range from 17-25ºC in the summer, and I currently only have readings on the 17-18 range.

Concerning the offset of DHTNew, I could easily just sum 1ºC to each temperature reading, without having to change the library.

Also, I have changed the VCC from 3.3V to 5V and the results are similar. The gap you see is the time it took to restart ESP01, connection to wifi, mqtt, etc image

My question is: Can I rule out a software issue that causes the readings to be smaller?

Nonetheless, I am thinking about changing to DHTnew because of its low-power features, since the goal is for these sensors to run in a battery, even though I am expecting the same sensor behaviour (after all, it is a fork of DHTstable).

Lastly, I could use one of the sensors you mentioned, but DHT22 is the best one-wire protocol based I know of, otherwise I can't use it with ESP01. Those you mentioned are I2C basted.

Thanks!

RobTillaart commented 3 years ago

About multimap, it could be a good solution, but I don't have a solid range of values for it to compute the interpolations

You could do the correct interpolation for the known part and later update the rest. Some people do a test with their fridge and freezer to get a larger range of data.

Concerning the offset of DHTNew, I could easily just sum 1ºC to each temperature reading, without having to change the library.

yes, is as simple as that. Or you can create a lookup table with known offsets, a bit like this:

int8_t offset[80]  // maps temp -20 to + 60;     (only uses 80 bytes)
{
  10, 11, 12, 11, 12, ....    1, 0, -3, -5, -9, -10, ....  // offsets are in steps of 0.1°C
};

float t = dht.temperature();
t = t + offset[t + 20] * 0.1;    // t+20 to get the right index
...

get the idea?

changed the VCC from 3.3V to 5V and the results are similar

As expected, although at 5V one might get self heating effects if you read more than once per 2 seconds.

My question is: Can I rule out a software issue that causes the readings to be smaller?

Definitely, the software just interprets the bit pattern send back by the hardware. There is some MCU inside the DHT sensor but I never heard about how to reprogram these.

after all, it is a fork of DHTstable

Although they share some core code, there is a difference. DHTStable will not get functionality updates (from me), and bugfixes only if there is a serious bug found. I completely moved to DHTNew for new developments.

Lastly, I could use one of the sensors you mentioned, but DHT22 is the best one-wire protocol based I know of, otherwise I can't use it with ESP01. Those you mentioned are I2C basted.

It is not the ONEWIRE protocol, which is from Dallas Semiconductor, but it does only use one wire. From the range of the DHT sensors you might consider a DHT44 (aka RHT05). Not mainstream and hard to find, probably obsolete.

When I only need temperature my favorite is the DS18B20 (the real ONEWIRE) , which is pretty precise and accurate.

Other questions?

afonsoc12 commented 3 years ago

I just tested with Adafruit's and its the same issue (while it is still working).

I am closing this issue.

Thanks!

RobTillaart commented 3 years ago

Ok, if there are other questions, just open a new issue.