Inaccurate humidity measurement with DHT22

Hello,

Yesterday I wired my AM2302 ( DHT22 in a plastic enclosure ), and to my surprise the humidity measurement is way off (about 10%).

Was I just unlucky, and got a crappy sensor?

Here’s the code I am using to connect to it.


#include "PietteTech_DHT/PietteTech_DHT.h"
#include "math.h"

#define DHTTYPE  AM2302       // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN   3           // Digital pin for communications
//#define NUM_TRACES 2 //There will be 4 data traces in the stream

//declaration
void dht_wrapper(); // must be declared before the lib initialization


// Lib instantiate
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);
bool odd;      // counter
double temp;  //temperatura era double  
double umid;  //umidità  era double
double t;   //mi serve per approx

void dht_wrapper() {
    DHT.isrCallback();
}

double humidity = 0, cTemp = 0;
String code = "";

void setup()
{
    Serial.begin(9600);

    Serial.println("Device starting...");

    //while (!Serial.available()) {
    //    Serial.println("Press any key to start.");
    //    delay (1000);
    //}
    Serial.println("DHT Example program using DHT.acquireAndWait");
    Serial.print("LIB version: ");
    Serial.println(DHTLIB_VERSION);
    Serial.println("---------------");
    
    Particle.variable("Humidity", humidity);
    Particle.variable("Temperature", cTemp);
    Particle.variable("code",code);
}


void loop()
{
    Serial.print(": Retrieving information from sensor: ");
    Serial.print("Read sensor: ");
    //delay(100);

    int result = DHT.acquireAndWait();
    
    switch (result) {
        case DHTLIB_OK:
            Serial.println("OK");
            code = "OK";
            break;
        case DHTLIB_ERROR_CHECKSUM:
            Serial.println("Error\n\r\tChecksum error");
                        code = "checksum error";
            break;
        case DHTLIB_ERROR_ISR_TIMEOUT:
            Serial.println("Error\n\r\tISR time out error");
                        code = "isr error";
            break;
        case DHTLIB_ERROR_RESPONSE_TIMEOUT:
            Serial.println("Error\n\r\tResponse time out error");
                        code = "response timeout err";
            break;
        case DHTLIB_ERROR_DATA_TIMEOUT:
            Serial.println("Error\n\r\tData time out error");
                        code = "data timeout err";
            break;
        case DHTLIB_ERROR_ACQUIRING:
            Serial.println("Error\n\r\tAcquiring");
                        code = "aquiringt error";
            break;
        case DHTLIB_ERROR_DELTA:
            Serial.println("Error\n\r\tDelta time to small");
                        code = "dt too small";
            break;
        case DHTLIB_ERROR_NOTSTARTED:
            Serial.println("Error\n\r\tNot started");
                        code = "not started";
            break;
        default:
            Serial.println("Unknown error");
                        code = "error";
            break;
    }

    Particle.publish("code", code, PRIVATE);
    if ( result != DHTLIB_OK )
        return;

    umid=DHT.getHumidity();


    Particle.publish("Humidity", String(umid),PRIVATE);

    temp=DHT.getCelsius();

    Particle.publish("Temperature", String(temp),PRIVATE);
    

    delay(15000);
}

The DHT-22 is a +/-5% RH device so you are not too far off. Other more expensive sensors, like the ones from Bosch are much are accurate in my experience.

Here are some things to check:

  • The DHT-22 is 3.3V minimum device but really likes 5V supply. I would try +5V supply if you have not already.

  • The sensor internal compensates the RH for temperature so if the temperature is reading high due to hot components nearby, you will get wrong RH readings. Try moving the sensor to a separate breadboard or as far as you can from other heat generating components up to say 12 inches away. The timing of the signals is critical with the sensor so you cannot go too far.

Here is a link to a data sheet:

Right.
I read the +/- 2%. Did not look at the max 5%. I prefered this sensor because of it’s enclosure.
This sensor goes inside very high humidity levels, ~80%. I had before an HIH6130, which got sprinkled directly and got stuck at 100% humidity.

Got any ideas of alternative sensors that can take such humidities?

Nothing works well in a 100% humidity environment due to condensation but the Bosch BME280 is spec’ed to work 0-100% humidity and give more accurate temperature (and atmospheric pressure as well). You can add a breathable membrane over the sensor hole in the part to keep stuff out but I have never needed it. It is an expensive but nice part.

Thanks for the help.

This is a bit late on the conversation, but I am also looking into HIH series humidity sensors and discovered something that might help you.

If you look at the data sheet for the HIH 6000 series, it shows that the version numbers that end with “1” include a membrane. Therefore, you might try out the HIH6131 which is exactly what you had before plus the membrane to protect against direct water contact.

I am about to try the HIH5031 (with the membrane), which is an analog humidity sensor and tying it to a 1-wire device with an ADC.
It turns out the wire length is too long in my application to use the DHT22, as one sensor is about 35 ft away from my Photon.
I found the BME280 works very well and the DHT22 works okay but only on short wire lengths.