Sub topic 10
Computing Heat Index and Dew Point
This chapter assumes you can wire a DHT11 or DHT22, install the Adafruit DHT library, read values in an Arduino sketch, and use the Serial Monitor. It also assumes you understand floating-point values such as float.
A DHT sensor gives you two direct measurements:
- Temperature, usually in degrees Celsius.
- Relative humidity, expressed as a percentage from 0 to 100.
These measurements can produce useful values that the sensor does not measure directly.
Heat index
Heat index estimates how hot the air feels to a person when temperature and humidity act together. High humidity slows the evaporation of sweat, so the same air temperature can feel hotter when humidity rises.
Heat index is most useful in warm conditions. At mild or cool temperatures, it may not be meaningful. It is also an estimate for human comfort, not a new physical temperature measurement.
The Adafruit DHT library provides the computeHeatIndex function. It accepts temperature, relative humidity, and an optional unit argument.
| Input | Meaning |
|---|---|
| Temperature | Celsius by default, or Fahrenheit when the third argument is true |
| Humidity | Relative humidity in percent |
| Result | Estimated heat index in the same temperature unit |
When using Celsius, pass false as the third argument. When using Fahrenheit, pass true or use the default Fahrenheit form shown below.
Dew point
Dew point is the temperature at which air becomes saturated with water vapor. If a surface is at or below the dew point, water can condense on it. This helps explain window condensation, mold risk, and outdoor fog.
The following function uses the Magnus approximation. It works well for common indoor and outdoor conditions.
float dewPointC(float temperatureC, float humidityPercent) {
const float a = 17.62;
const float b = 243.12;
float gamma = log(humidityPercent / 100.0)
+ (a * temperatureC) / (b + temperatureC);
return (b * gamma) / (a - gamma);
}The humidity must be greater than zero because the logarithm of zero is undefined. A normal DHT reading satisfies this condition. Check the reading before calling the function.
Complete example
This sketch reads the sensor, calculates heat index in both units, and calculates dew point in Celsius.
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float dewPointC(float temperatureC, float humidityPercent) {
const float a = 17.62;
const float b = 243.12;
float gamma = log(humidityPercent / 100.0)
+ (a * temperatureC) / (b + temperatureC);
return (b * gamma) / (a - gamma);
}
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
delay(2000);
float humidity = dht.readHumidity();
float temperatureC = dht.readTemperature();
float temperatureF = dht.readTemperature(true);
if (isnan(humidity) || isnan(temperatureC) || isnan(temperatureF)) {
Serial.println(F("Sensor read failed."));
return;
}
float heatIndexC = dht.computeHeatIndex(temperatureC, humidity, false);
float heatIndexF = dht.computeHeatIndex(temperatureF, humidity);
float dewPoint = dewPointC(temperatureC, humidity);
Serial.print(F("Temperature: "));
Serial.print(temperatureC);
Serial.print(F(" C / "));
Serial.print(temperatureF);
Serial.println(F(" F"));
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.println(F(" %"));
Serial.print(F("Heat index: "));
Serial.print(heatIndexC);
Serial.print(F(" C / "));
Serial.print(heatIndexF);
Serial.println(F(" F"));
Serial.print(F("Dew point: "));
Serial.print(dewPoint);
Serial.println(F(" C"));
}Interpreting the results
Treat derived values as estimates. A DHT11 is relatively slow and less accurate than a DHT22. Sensor placement also matters. Direct sunlight, nearby heat sources, airflow, and touching the sensor can distort both input readings and every calculated result.
Do not calibrate the heat index or dew point independently. If the temperature or humidity reading has an offset, correct those raw values first, then calculate the derived values.
Exercise
A reading is 28 degrees Celsius with 70 percent relative humidity. Should you describe the heat index as the sensor's measured temperature?
Show answer
No. The sensor measured 28 degrees Celsius. The heat index is a calculated estimate of how warm that combination may feel.