heat index formula

Heat Index Formula

A ready-made heat index formula for your DIY weather station.

Weather stations are a popular DIY project for microcontroller hobbyists. Sensors are readily available and easy to interface with. While developing my own weather station, I implemented this heat index formula. I thought I’d share it with you. The longer I work on the weather station, the more I add to it. When it’s complete I’ll write it up if there’s interest. So far, it’s a solar-charged, 18650-powered device with an OLED display which provides wind speed, peak wind speed for the day, wind direction, rainfall for the day, temperature, humidity, barometric pressure, barometric trend, UV index, and light levels. And I have pins left, so clearly I need to add more to it!

If you have sensors to give you the temperature and the humidity, you can use the heat index formula to get a “feels like” temperature value from your weather station. If you don’t have temperature and humidity sensors, take a look at the simple sensors out there, in order of increasing accuracy, the DHT11, DHT22, and BME280 (which also provides barometric pressure).

The Heat Index formula gives you a subjective temperature value that reflects the perceived effect of humidity on temperature. It is based on assumptions about clothing, perspiration, body weight, light intensity, and other factors. These assumptions may decrease the accuracy of the heat index formula, but they make it much simpler to implement. More complex formulas exist. Using the temperature and two or more other factors (like humidity and wind speed) is patented in the U.S. by Accuweather. To avoid patent infringement issues, I’m sharing the formula used by the National Oceanic and Atmospheric Administration’s National Weather Service (NOAA’s NWS if you like acronyms). As a reference, here is a link to the NWS heat index formula page.

This function is written in C, so it should be portable to many applications. I wrote it specifically for the ESP-8266 in the Arduino IDE. Feel free to copy and paste away:

/**
 * heatIndex
 * @return heat index in degrees F
 */
float heatIndex() {
  //Reference: https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
  //curTemp = current temp in degrees F; curHumidity = relative humidity in percent; both type float
  
  //Use short formula if less than 80
  float shortHi = 0.5 * (curTemp + 61 + ((curTemp - 68) * 1.2) + (curHumidity * 0.094));
  if((shortHi + curTemp) / 2 < 80) {
    return shortHi;
  }
  
  //Otherwise use long version
  float hi = -42.379 + (2.04901523 * curTemp) + (10.14333127 * curHumidity) - (0.22475541 * curTemp * curHumidity) - 
             (6.83783 * pow(10,-3) * pow(curTemp,2)) - (5.481717 * pow(10,-2) * pow(curHumidity,2)) +
             (1.22874 * pow(10,-3) * pow(curTemp,2) * curHumidity) + (8.5282 * pow(10,-4) * curTemp * pow(curHumidity,2)) -
             (1.99 * pow(10,-6) * pow(curTemp,2) * pow(curHumidity, 2));
  float adj = 0.0;

  if(curHumidity < 13) {
    adj = ((13 - curHumidity) / 4) * sqrt((17 - abs(curTemp - 95)) / 17);
  }
  else if(curHumidity > 85 && curTemp >= 80 && curTemp <= 87) {
    adj = ((curHumidity - 85) / 10) * ((87 - curTemp) / 5);
  }
  
  return hi - adj;
}
Cover photo by Nick Karvounis on Unsplash

Leave a Reply

Your email address will not be published.