[Solved] DHT12 humidity drifting +10% from commercial sensor

Hi, I'm trying to connect an ESP8266 with a DHT12 using I2C, and I'm having values which feel wrong.

So, to exclude an error in the libraries out there, I tried writing the simplest code using an Arduino UNO to be sure. To double check, I have 2 DHT12 (fed using the 3.3v pin), and a commercial temperature and humidity thermostat bought on Amazon.

My Arduino UNO outputs: Humidity 19.3%, Temperature 21.2°C.
While my Amazon thermostat shows 36% humidity, 21.3°C.

The temperature seems perfect, sometimes being 1°C off, which isn't an issue. But the humidity being almost 25% off is strange, the second sensor detecting exactly the same values as the first one.

Here is my code:

#include    <Wire.h>

#define     DHT12_ADDR      0x5c

byte            dht12_data[5];

void    setup()
{
    digitalWrite(A4, INPUT_PULLUP);
    digitalWrite(A5, INPUT_PULLUP);

    Serial.begin(115200);
    while(!Serial);
    Serial.println(F("Serial ready"));

    Wire.begin();
    Serial.print(F("Preparing the sensor: "));
    delay(2000);                                // Cross unstable state
    Wire.beginTransmission(DHT12_ADDR);
    Wire.write(0);
    if (Wire.endTransmission() != 0) {
        Serial.println(F("Error checking sensor. Stop"));
        while(1);
    }
    Serial.println(F("Sensor online"));

    Serial.print(F("Requesting last read from previous check: "));
    Wire.requestFrom(DHT12_ADDR, 5);
    for (byte i=0; i<5; ++i) {
        dht12_data[i] = Wire.read();
    }
    if (Wire.available() != 0) {
        Serial.println(F("More than 5 bytes received. Stop"));
        while(1);
    }
    if (dht12_data[0] + dht12_data[1] + dht12_data[2] + dht12_data[3] != dht12_data[4]) {
        Serial.println(F("Checksum failed. Stop"));
        while(1);
    }
    for (byte i=0; i<5; ++i) {
        Serial.print(dht12_data[i], DEC);
        Serial.print(F(", "));
    }
    Serial.println();

    Serial.print(F("Humidity: "));
    Serial.print(dht12_data[0], DEC);
    Serial.write('.');
    Serial.print(dht12_data[1], DEC);
    Serial.println();

    Serial.print(F("Temprature: "));
    Serial.print(dht12_data[2], DEC);
    Serial.write('.');
    Serial.print(dht12_data[3], DEC);
    Serial.println();

    Serial.println(F("End"));
}

void    loop()
{
    //
}

I've attached a picture of how I connected everything (holes on the sensor facing right), hoping the proximity of the wires isn't an issue.

Am I missing something? Are there more faulty sensors as usual in this brand, or faulty in the same series (I'm sure my 2 sensors are from the same series)?

Thanks for your help

Both could be wrong. Get a psychrometer and verify what the real value is.

Paul

Maybe the answer is simply that the DHTs are not commercial grade, and if you want reliable data you need quality equipment?

Paul_KD7HB:
Both could be wrong.

What do you mean by « both »? Both « sensors » + the Amazon « Home thermostat » I bought to compare? Or just the 2 DHT-12?

Willpatel_Kendmirez:
Maybe the answer is simply that the DHTs are not commercial grade, and if you want reliable data you need quality equipment?

I understand that and of course, a 3€ sensor may not be super reliable, but what I can’t understand is that the datasheets online say 5% precision on humidity, 0.5° precision on temperature. And I’m precisely have 0.5°C difference, and 3 times the expected difference on humidity... I want to make my basic heater and my basic humidity remover connected, while I can tolerate few degrees off, 15% on humidity is too much to know when to start the remover.

Moreover, it also doesn’t seem to be “shifted”.

According to the seller, i’m The first one complaining about their values, and because 2 of them output the exact same values, he blames my amazon thermostat (https://www.amazon.fr/gp/aw/d/B07717GJD8?psc=1&ref=yo_pop_mb_yo_pop_mb_pd_t2), which I’m also starting to blame because it stays on the same values, after having put drying clothes in the room 2 days ago...

BTW @Paul_KD7HB, is my thermostat not reliable enough for a psychrometer to be needed?

"BTW @Paul_KD7HB, is my thermostat not reliable enough for a psychrometer to be needed?".

It's needed only if you want a calibration value to work from.

Paul

That "commercial" thermostat is probably no better than your DHT12.

Improper ventilation and lack of exposure to ambient air (and not your breath) are other possible causes of wrong readings.

You could look at better humidity sensors. The BME280 is one commonly mentioned here, and it seems to be pretty accurate. Still not expensive, either.

Paul_KD7HB:
"It’s needed only if you want a calibration value to work from.

Are you saying that the DHT12 could give not incorrect but shifted values? :smiley:

@wvmarle: Please explain « lack of ventilation ». Is it not capable of sending « static » air? I’m asking because I was also thinking about « how » I could make my enclosure. The amazon thing seemed to be completely closed without holes (while it was certainly not watertight, i’m Not sure how it could sense humidity...). And ultimately I’d like to make an enclosure for my project, with a hole for the screen, for a USB to reprogram it and batteries. I don’t know what are the requirements for the sensors to be effective, should they be « outside » of the enclosure, on an edge visibly but without being out, or closed in a box is good?

Anyway, it’s currently on a breadboard, on my desk. I don’t move a lot, I don’t make a lot of air movement, is that what you’re talking about when you say « lack of ventilation » ?

ÉDIT: Bought a BME280 to be sure.

For a sensor like humidity/temperature of course that sensor must be exposed to the humidity/temperature you want it to measure. If you enclose it in a box you measure the humidity and temperature inside that box, which may or may not be what you want.

Polymer humidity sensors take a long time to recover from high humidity back down to low
humidity - so you may have to wait longer than you think. Forced air-flow over both sensors
will equalize them much better than static air conditions.

Ultimately these devices are cheap and cheerful. Wet/dry bulb hygrometer is much more accurate,
although cumbersome.

MarkT:
Forced air-flow over both sensors will equalize them much better than static air conditions.

Ultimately these devices are cheap and cheerful. Wet/dry bulb hygrometer is much more accurate,
although cumbersome.

Thanks for your precisions. Indeed, they're cheap, but what I couldn't understand is the difference in temperature and humidity precisions.

I've asked a friend to bring me his calibrated sensor (which can be wall mounted or stand on a table), which seems to be calibrated (because he also checked with his humidity extractor), and the difference with his and my DHT12 seems to be constant (DHT12 is 9.8 to 10% lower). I'll give him mine for a few days (with the offset hard-coded) and let him tell me how it is.

Thank you all for your help

what I couldn't understand is the difference in temperature and humidity precisions.

It is technically much easier to accurately measure temperature than humidity.

I understand that now. I'm happy to have found that the shift is a fixed offset

That fixed offset will no doubt go wrong when you have a particularly dry day (<30% humidity or so).

Ok ok. I understand that the humidity part of the DHT12 is lost. I’m waiting for a BME280, i hope this one is better