# About Humidity

When you use a temperature, pressure and humidity sensor with a Raspberry Pi, Arduino or ESP computer you'll probably be using a Bosch BME280 that's mounted on some sort of breakout board.

For relative humidity it gives a percentage value between 0 and 100. Put simply, this is the ratio of the amount of water that the air actually contains to the maximum amount it could contain at a given temperature. The at a given temperature is important here because the relative humidity of air will decrease as temperature rises because warm air can hold more water vapour than cold air. This is why clouds form when warm moist air is forced upwards by mountains - the air cools and it cannot continue to hold its water vapour and so it condenses into droplets and rains.

It is not meaningful to try to compare the relative humidity in different locations unless the temperatures are the same. Likewise, an average relative humidity is only valid if the readings were all taken at the same temperature.

A better comparison would be to compare absolute humidity values, also known as vapour densities, which are the actual amounts of water in the air in kg/m^{3} or, more
usefully, g/m^{3}. However,
converting relative humidity to absolute humidity requires some maths.

The graph below is real data collected outside in the UK in June 2020 and lets you compare relative humidity and absolute humidity, It shows atmospheric pressure in green, temperature in red, relative humidity in blue and absolute humidity in pink. Note that, as explained above, relative humidity and temperature vary inversely. Here, the actual amount of water in the air, absolute humidity, is reasonably constant throughout the day.

## The Calculation

The first step to calculate the absolute humidity value is to find the saturated vapour pressure for water at the air temperature at which you're measuring relative humidity. This needs two dimensionless constants 17.502 and 240.97, which are for water at 0C or above; they're different for air below zero but we're not interested with that situation here but the constants for air below 0°C are in the footnote. These constants are found by experimentation and so will vary depending upon the reference material. Temperature is the air temperature in C.

Note that exp(â€¦) means e^{ (â€¦)}.

Next, we need to find the relative vapour pressure, which is just the relative humidity multiplied by the saturated vapour pressure.

We can now calculate the absolute humidity in kg/mÂ³ but also need some additional information:

- Molecular weight of water, which is 18.02 g/mol
- Universal gas constant, which is 8.31 J/mol/K

The equation for absolute humidity is:

Note here that the air temperature is in K, not C, because it has to cancel out with the K in the universal gas constant. To convert C to K you add 273.15.
The other units like Joules
can be converted 1:1 into Nm and Pascals can be converted 1:1 into N/m^{2}, which all cancel conveniently
to give an absolute humidity or vapour density in g/m^{3}. We get g/m^{3} and not kg/m^{3} because the molecular weight of water is in g per mole.

In my wireless sensor network the absolute humidity is calculated on board the ESP8266s (in my case) and made available for download via HTTP in the same way as any other measurement. It is then stored on a Pi and used to create daily plots for different locations.

## Graphical Calculation Of Absolute Humidity

You can use the equations above to calculate absolute humidity or, for a quick assessment, use the graph below. Look for the temperature on the X-axis then draw an imaginery line up until you hit the curve that corresponds to your relative humidity then read off the absolute humidity on the Y-axis.

## Footnote

For air temperatures below 0°C, you should use the following dimensionless constants: 21.875 instead of 17.502 and 265.5 instead of 240.97.