Compute Heat Index with Arduino and DHT Sensor

 Author:   Posted on:   Updated on:  2018-01-07T16:27:29Z
The heat index is a parameter that takes into account temperature and relative humidity, to determine the apparent temperature or the human perceived equivalent temperature. Heat index was developed in 1978 by George Winterling and was adopted next year. It is also known as humiture, according to Wikipedia contributors.

To compute this index, you need to know current temperature and relative humidity. An easy way to find both is by using an Arduino development board with a DHT sensor (DHT11, DHT22). These sensors measure temperature and humidity and send it to the microcontroller using a digital protocol. Thus, there is no need for calibration. You can read the values directly from the sensor module.

However, you should take into account that the accuracy of these sensors is not the best. DHT11 has an accuracy of +/-5% for humidity and +/-2 degrees Celsius for temperature. DHT22 (AM2302) is slightly better with an accuracy of +/-2% for humidity and +/-0.5 degrees Celsius for temperature. More than that, DHT22 has extended ranges for both temperature and humidity.

Compute Heat Index with Arduino and DHT Sensor
Besides the sensor, you need some way of displaying the heat index value. I used an LCD, but for a test setup, you can send data through serial port. Here is how you should connect things:

Measure temperature and humidity with Arduino and DTH11/22
Measure temperature and humidity with Arduino and DTH11/22
Once you got all this together, you need to program the Arduino. Heat index formula is not that easy. The equations were developed by Rothfusz and Steadman and you can find them at National Weather Service. Luckily, both equations are included in Adafruit DHT library. You can install this library from Arduino IDE using the Library Manager. The code becomes very easy now:
#include <DHT.h>
#include <LiquidCrystal.h>

// #define USE_FAHRENHEIT

#define DEGREE_SYMBOL (char)223
#define DHTPIN 2
#define DHTTYPE DHT11
#ifdef USE_FAHRENHEIT
#define DEGREE_UNIT 'F'
#else
#define DEGREE_UNIT 'C'
#endif

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  pinMode(10, INPUT); // needed only by LCD-keypad shield

  lcd.begin(16, 2);
  dht.begin();

  lcd.setCursor(0, 0);
  lcd.print("HI=");
  lcd.setCursor(0, 1);
  lcd.print("T=");
  lcd.setCursor(10, 1);
  lcd.print("RH=");
}

void loop() {
  delay(2000);

  float humidity = dht.readHumidity();
#ifdef USE_FAHRENHEIT
  float temperature = dht.readTemperature(true);
#else
  float temperature = dht.readTemperature(false);
#endif

  if (isnan(humidity) || isnan(temperature))
    return;

#ifdef USE_FAHRENHEIT
  float hi = dht.computeHeatIndex(temperature, humidity, true);
#else
  float hi = dht.computeHeatIndex(temperature, humidity, false);
#endif

  lcd.setCursor(2, 1);
  lcd.print(temperature, 1);
  if ((temperature < 100) && (temperature > 0))
    lcd.setCursor(6, 1);
  else
    lcd.setCursor(7, 1);
  lcd.print(char(223));
  lcd.print(DEGREE_UNIT);

  lcd.setCursor(13, 1);
  lcd.print((int)humidity);
  lcd.print('%');

  lcd.setCursor(3, 0);
  lcd.print(hi, 2);
  lcd.print(char(223));
  lcd.print(DEGREE_UNIT);
}
The sketch will display values in Fahrenheit degrees if you uncomment #define USE_FAHRENHEIT. If you use a different sensor, change DHTTYPE definition at the beginning.

The equations can be found in the library code, which is distributed under MIT license.
hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (percentHumidity * 0.094));

if (hi > 79) {
    hi = -42.379 +
             2.04901523 * temperature +
            10.14333127 * percentHumidity +
            -0.22475541 * temperature*percentHumidity +
            -0.00683783 * pow(temperature, 2) +
            -0.05481717 * pow(percentHumidity, 2) +
             0.00122874 * pow(temperature, 2) * percentHumidity +
             0.00085282 * temperature*pow(percentHumidity, 2) +
            -0.00000199 * pow(temperature, 2) * pow(percentHumidity, 2);

    if((percentHumidity < 13) && (temperature >= 80.0) && (temperature <= 112.0))
      hi -= ((13.0 - percentHumidity) * 0.25) * sqrt((17.0 - abs(temperature - 95.0)) * 0.05882);

    else if((percentHumidity > 85.0) && (temperature >= 80.0) && (temperature <= 87.0))
      hi += ((percentHumidity - 85.0) * 0.1) * ((87.0 - temperature) * 0.2);
  }
As you can see, the code follows both Rothfusz regression and Steadman equation.

No comments :

Post a Comment

Please read the comments policy before posting.