Sub topic 1
What Temperature and Relative Humidity Measure
Before you wire a sensor or call a library function, you need to know what the two numbers it returns mean. Many wrong readings, and many wrong conclusions drawn from correct readings, come from treating relative humidity as if it were a fixed amount of water. This chapter builds the physical model that the rest of the tutorial relies on.
Prerequisites
This chapter assumes you can already do the following:
- Write and upload a basic sketch with
setup()andloop(). - Open the Serial Monitor and read printed output.
- Place components on a breadboard.
- Use basic C++ types such as
floatandint.
No sensor hardware is needed here. The only code is a short sketch that prints to the Serial Monitor.
Temperature: what the number says
Temperature describes how much thermal energy the molecules of a material carry on average. A sensor does not measure molecules directly. It measures a property that changes predictably with temperature. The DHT11 and DHT22 sensors use a thermistor, a resistor whose resistance falls as it warms. The sensor's chip converts that resistance into a number.
Three scales are in common use:
| Scale | Unit | Water freezes | Water boils (sea level) | Typical use |
|---|---|---|---|---|
| Celsius | °C | 0 | 100 | Most of the world, most sensor datasheets |
| Fahrenheit | °F | 32 | 212 | US weather and consumer products |
| Kelvin | K | 273.15 | 373.15 | Physics formulas |
Two points matter for sketches:
- A sensor reports the temperature of the sensor body, not of "the room". If the body is warmer or cooler than the air around it, the reading is off by that difference. Later chapters cover the causes.
- The sensor needs time to reach the temperature of its surroundings. Carry it from a cold porch into a warm kitchen and the reading drifts for a while. This delay is called thermal lag.
Humidity: three different quantities
"Humidity" can mean several things, and the sensors you will use report only one of them.
- Absolute humidity is the mass of water vapor in a given volume of air, in grams per cubic meter. It does not change when you heat or cool a sealed volume of air.
- Relative humidity (RH) is the amount of water vapor in the air as a percentage of the most vapor the air could hold at its current temperature. This is what DHT sensors report.
- Dew point is the temperature at which air becomes saturated and water starts to condense. It is a temperature, not a percentage. A later chapter computes it.
RH is defined as a ratio of two pressures:
RH (%) = 100 × e / e_s(T)Here e is the actual partial pressure of water vapor in the air. e_s(T) is the saturation vapor pressure, which is the largest partial pressure of water vapor possible at temperature T. At 100% RH the air is saturated. Extra moisture condenses into liquid.
The humidity element in a DHT sensor is a capacitor with a moisture-absorbing polymer between its plates. The polymer takes up water in proportion to the surrounding RH, and that changes the capacitance. The sensor's chip converts the capacitance into a percentage.
Why the two readings are linked
The saturation vapor pressure e_s(T) rises steeply with temperature. Warm air can hold much more water vapor than cold air. So the same water content gives a lower RH when the air is warm and a higher RH when it is cool.
A common approximation of e_s in hectopascals (hPa), valid for roughly -45 °C to 60 °C, is the Magnus formula:
e_s(T) = 6.112 × exp(17.62 × T / (243.12 + T))Here is a worked example. A room is at 30 °C with 50% RH.
e_s(30 °C)is about 42.3 hPa.- The actual vapor pressure is
e = 0.50 × 42.3 ≈ 21.2 hPa. - Cool the same air to 20 °C without adding or removing any water.
estays at 21.2 hPa. e_s(20 °C)is about 23.3 hPa.- The new RH is
21.2 / 23.3 ≈ 91%.
The air did not gain any water, yet RH rose from 50% to 91%. If it cooled to about 18.5 °C, RH would reach 100% and moisture would begin to condense.
Checking the model in a sketch
You can verify the numbers above on an Arduino. The sketch below implements the Magnus formula and calculates the RH that results when air at a known temperature and RH is cooled. It needs no sensor and runs once.
float saturationVaporPressureHpa(float tempC) {
return 6.112 * exp((17.62 * tempC) / (243.12 + tempC));
}
float rhAfterTemperatureChange(float startTempC, float startRh, float endTempC) {
float vaporPressure = (startRh / 100.0) * saturationVaporPressureHpa(startTempC);
return 100.0 * vaporPressure / saturationVaporPressureHpa(endTempC);
}
void setup() {
Serial.begin(9600);
float rh = rhAfterTemperatureChange(30.0, 50.0, 20.0);
Serial.print(F("RH after cooling from 30 C to 20 C: "));
Serial.print(rh);
Serial.println(F(" %"));
}
void loop() {
}The Serial Monitor should show a value close to 91 percent. The sketch keeps the vapor pressure fixed and changes only the temperature. That is the relationship a real sensor reflects every time it reports a pair of numbers.
What this means for the readings you will take
The model above has practical consequences.
- RH always comes paired with a temperature. An RH value on its own says little. 60% RH at 10 °C holds far less water than 60% RH at 30 °C. Log both values together.
- Your own sensor can distort RH. A sensor body heated by a nearby voltage regulator, a motor driver, or direct sunlight reads warmer than the air. The air around the warm sensor body is warmer than the room, so it reports lower RH than the room really has. Mount the sensor away from heat sources and give it airflow.
- RH has hard limits. It cannot go below 0% or above 100% in physical reality. A reading slightly outside the range is a sensor error, not weather. The calibration example later in the tutorial clamps values to this range.
- Condensation is a failure condition. At or near 100% RH, water can form on the sensor. Most DHT sensors are not designed for continuous condensing conditions, and readings can be wrong until the sensor dries.
- Temperature changes fast, humidity changes slowly. The polymer takes time to absorb or release water. After a sudden change in the environment, the RH reading can take tens of seconds to settle.
Common errors
| Mistake | Why it is wrong | What to do instead |
|---|---|---|
| Treating RH as "how much water is in the air" | RH depends on temperature as well as water content | Think of it as a percentage of capacity at the current temperature |
| Comparing RH from two places at different temperatures | The same absolute humidity gives different RH | Compare dew point or absolute humidity instead |
| Trusting a reading taken seconds after moving the sensor | Thermal lag and slow polymer response | Wait for the readings to settle |
| Mounting the sensor next to the Arduino board or a regulator | Self-heating raises temperature and lowers RH | Move it away and give it open air |
| Expecting the numbers to be exact | Each sensor has a stated accuracy, such as ±2% RH for a DHT22 | Read the datasheet and calibrate if needed |
| Mixing units when comparing results | Celsius and Fahrenheit differ by more than a constant | Fix one unit across your code and logs |
Where this fits in the tutorial
The next chapter introduces the DHT11 and DHT22, the two sensors that produce these two numbers. Later chapters return to this model when they compute dew point and heat index from a temperature and RH pair, and when they discuss accuracy and calibration.
Exercise
Air at 25 °C has 60% RH. You warm it to 35 °C without adding or removing water. Will RH rise, fall, or stay the same? Explain without calculating exact numbers.
Show answer
RH falls. The water vapor pressure stays the same, but the saturation vapor pressure rises sharply with temperature. The ratio of actual to saturation pressure therefore gets smaller. For reference, e_s is about 31.7 hPa at 25 °C and about 56.3 hPa at 35 °C, so RH drops to about 34%.
Exercise
Your DHT22 sits 2 cm from a voltage regulator that warms the air around it by 4 °C. The room is at 22 °C and 50% RH. Does the sensor report an RH that is higher than, lower than, or equal to the room's RH, and why?
Show answer
Lower. The air around the sensor is warmer than the room, but it holds the same amount of water vapor. Saturation vapor pressure is higher at the warmer temperature, so the same vapor pressure is a smaller fraction of it. The sensor reports a lower RH, and a temperature that is also too high.