Hemidex (heat index) - DHT11

Anyone got hemidex (heat index) code that I could add to my project? I'm using a DHT11 for my temp. and humidity.

I know there is hemidex code out there, but it is all integrated into other projects and I don't know what I need to pull out (i.e. what is needed to calculate hemidex). Currently, I'm able to display the temperature in both C and F, the humidty and the dewpoint to my LCD shield. I'd like to be able to add hemidex.

I'd actually like to be able to use the hemidex values rather than the temp values for other commands.

Thanks

Sorry, here is some of the code I am currently using.

#include "DHT.h"

//Temperature & Humidity
#define DHTPIN 2

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

double dewPoint(double celsius, double humidity) {
  double A0= 373.15/(273.15 + celsius);
  double SUM = -7.90298 * (A0-1);
  SUM += 5.02808 * log10(A0);
  SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
  SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
  SUM += log10(1013.246);
  double VP = pow(10, SUM-3) * humidity;
  double T = log(VP/0.61078);   // temp var
  return (241.88 * T) / (17.558-T);
}

void setup() {
dht.begin();
}

void loop() {
  //Temperature & Humidity
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("*-- Failed to read T&H --*");
  }
  else {
    Serial.print("Temp (F): ");
    Serial.print(t*9/5 + 32);
    Serial.println(" *F");
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.println("% ");
    Serial.print("Temp (C): ");
    Serial.print(t);
    Serial.println(" *C");
    Serial.print("Dew Point: ");
    Serial.print(dewPoint(t, h));
    Serial.println(" *C");
  }

pretty simple math!

humi = dht.readHumidity(); // humidity from DHT
  tempf = dht.readTemperature(1);  //  has to bem in F
  HI = c1+c2*(tempf)+c3*(humi)+c4*(tempf)*(humi)+c5*(pow(tempf,2))+c6*(pow(humi,2))+c7*(pow(tempf, 2))*(humi)+c8*(tempf)*(pow(humi, 2))+c9*(pow(tempf, 2))*(pow(humi, 2));  // the heatindex formula
  HIc = ((((HI)-32)*5)/9);  //  converting to C

#define c1 (-42.379)
#define c2 (2.04901523)
#define c3 (10.14333127)
#define c4 (-0.22475541)
#define c5 (-0.00683783)
#define c6 (-0.05481717)
#define c7 (0.00122874)
#define c8 (0.00085282)
#define c9 (-0.00000199)

hope it helps.

g2tec has definitely better constants, but the code below will run faster as it minimizes the math operators.

// T = temp in F
// R = humidity in %
double heatIndex(double T, double R)
{
  double c1 = -42.38, c2 = 2.049, c3 = 10.14, c4 = -0.2248, c5= -6.838e-3, c6=-5.482e-2, c7=1.228e-3, c8=8.528e-4, c9=-1.99e-6  ;

  double A = (( c5 * T) + c2) * T + c1;
  double B = (((c7 * T) + c4) * T + c3) * R;
  double C = (((c9 * T) + c8) * T + c6) * R * R;

  return A + B + C;
}

// bonus ;)
double humidex(double tempC, double DewPoint)
{
  double e = 19.833625 - 5417.753 /(273.16 + DewPoint);
  double h = tempC + 3.3941 * exp(e) - 5.555;
  return h;
}

an even faster approximation is possible by removing all higher order elements of the equation.

double heatIndexFast(double T, double R)
{
  double c1 = -42.38, c2 = 2.049, c3 = 10.14, c4 = -0.2248;

  double A = c2 * T + c1;
  double B = (c4 * T + c3) * R;

  return A + B;
}

see also - http://arduino.cc/forum/index.php/topic,107569.msg807598.html#msg807598 -

robtillaart, thanks for the help making the code smaller and faster.
I'm developing a simple on-board automotive computer and the shinking of the formula is of great help.

Thanks again!

the approximation version can even be made faster by using integer math only (as possible)

not tested but it would be something like this. (used g2tec consts to get the integer values * 1024)

int heatIndexFast(int T, int R)
{
  long c1 = -43396, c2 = 2098, c3 = 10387, c4 = -230;  // consts multiplied by 1024

  long A = c2 * T + c1;  // so A is x 1024
  long B = (c4 * T + c3) * R;  // and B too

  return (A + B + 512) / 1024; // division becomes a shift; +512 is for rounding
}

disclaimer not tested if removing all the higher order elements gives the same (enough) output.