DHT22 sensor - humidity reading rubbish?

I've Googled for threads about the DHT22, there seem to be a lot! However I think my problem is a bit different. If not, please point me to a relevant link.

I've got a DHT22 (from Adafruit) mounted on a custom board, and after a bit of mucking around because the clock was running at 8 Mhz got readings from it. I know I should post all my code, but really the relevant lines are:

  humidity    = dht.readHumidity();
  temperature = dht.readTemperature();

The rest is infrastructure to log the results to an SD card, etc.

Now the temperature is OK, within a degree or two of other measurements. But the humidity just looks like the inverse of the temperature, eg.

You can see that from about 9 pm onwards, when we turned the heating off, the temperature dropped slowly. And next morning, with the heating back on, it climbed again fairly sharply.

But the humidity seems to be doing the opposite! I can't really believe that a closed room will gradually increase in humidity like that during the night, and then that it would drop back again next morning.

I thought maybe "bad code" or "bad wiring" but I found this other site:


And he had an almost identical chart:

Is there some sort of temperature compensation you are supposed to apply to the humidity figure? It just doesn't look right.

The DHT22 sensor measures RH (relative humidity). Relative humidity is a measure of the amount of water vapour that air can hold at a given temperature. If the temperature in a room goes down , then the RH in the room will go up, as the air which is getting colder can now hold far less water vapour . For a fixed amount of water vapour in the air in a closed space, such as a sealed room, then the RH will simply be an inverse of the room temperature.

So it's correct? I suppose that makes sense.

When you say the amount of water vapour the air "can hold" that doesn't mean it is holding it then?

It's still the same air, no-one has squirted water vapour into it.

Yes thats right. For air at a fixed temperature, there is a maximum amount of water vapour that the air can hold before water will start to condense out of the air. In this case a RH humidity sensor will read 100%. If the air is then heated, it can hold more water vapour, so the RH sensor will now read less than 100%. The actual amount of water vapour hasnt changed.

There are other types of humidity sensors called absolute humidity sensors which read the actual amount of water vapour in the air , but they usually read in grams per cubic meter, and as such arnt affected by the air temperature.

OK, so if we are looking at protecting something value (eg. documents) from mould, mildew, that sort of thing, then we would want the relative humidity to be less than 100%, since the air can hold the water in it (whatever that amount is) without it condensing?

So the relative humidity would go up either because it is colder, or because there actually is more water vapour there already? So for example on a hut humid day, you would expect relative humidity to go up, because although it is hotter, the air has to hold more. Do I have it right?

It looks like this might be relevant to my concerns:


This is good definition of RH. http://graphical.weather.gov/definitions/defineRH.html

You could test the RH by breathing to the sensor a few times, exhaled air has more water than inhaled. it should response

OK, so if we are looking at protecting something value (eg. documents) from mould, mildew, that sort of thing, then we would want the relative humidity to be less than 100%, since the air can hold the water in it (whatever that amount is) without it condensing?

far under the 100%!!
As it is a physical process (think differential equation) there is a constant condensing and evaporation at all levels of RH. When the RH is low the condensing and evaporation are in balance or in favor of evaporation. When the RH increases the balance shifts.

What is important to know is the dew point and how far you are away from it.

// reference: http://wahiduddin.net/calc/density_algorithms.htm 
double dewPoint(double celsius, double humidity)
        double RATIO = 373.15 / (273.15 + celsius);  // RATIO was originally named A0, possibly confusing in Arduino context
        double SUM = -7.90298 * (RATIO - 1);
        SUM += 5.02808 * log10(RATIO);
        SUM += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
        SUM += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
        SUM += log10(1013.246);
        double VP = pow(10, SUM - 3) * humidity;
        double T = log(VP/0.61078);   // temp var
        return (241.88 * T) / (17.558 - T);

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity/100);
        double Td = (b * temp) / (a - temp);
        return Td;

Hope this helps

Thanks, Rob. I might add a dew point calculation as well.

a small performance incr. in dewPointFast()

        double temp = (a * celsius) / (b + celsius) + log(humidity *0.01);

I'm using the "slow" dew point but thanks anyway.

Here are the latest figures with the dew point in them:

As you can see my heater goes crazy during the day, and then at night it gradually cools down.