Skip to content

Commit ffac2f1

Browse files
committed
Update example to show temp in Fahrenheit and add computeHeatIndex function to resolve issue #9.
1 parent 633eb08 commit ffac2f1

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

DHT.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ float DHT::readHumidity(void) {
7474
return NAN;
7575
}
7676

77+
float DHT::computeHeatIndex(float tempFahrenheit, float percentHumidity) {
78+
// Adapted from equation at: https://github.com/adafruit/DHT-sensor-library/issues/9 and
79+
// Wikipedia: http://en.wikipedia.org/wiki/Heat_index
80+
return -42.379 +
81+
2.04901523 * tempFahrenheit +
82+
10.14333127 * percentHumidity +
83+
-0.22475541 * tempFahrenheit*percentHumidity +
84+
-0.00683783 * pow(tempFahrenheit, 2) +
85+
-0.05481717 * pow(percentHumidity, 2) +
86+
0.00122874 * pow(tempFahrenheit, 2) * percentHumidity +
87+
0.00085282 * tempFahrenheit*pow(percentHumidity, 2) +
88+
-0.00000199 * pow(tempFahrenheit, 2) * pow(percentHumidity, 2);
89+
}
90+
7791

7892
boolean DHT::read(void) {
7993
uint8_t laststate = HIGH;

DHT.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class DHT {
3333
void begin(void);
3434
float readTemperature(bool S=false);
3535
float convertCtoF(float);
36+
float computeHeatIndex(float tempFahrenheit, float percentHumidity);
3637
float readHumidity(void);
3738

3839
};

examples/DHTtester/DHTtester.ino

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ void loop() {
2828
// Reading temperature or humidity takes about 250 milliseconds!
2929
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
3030
float h = dht.readHumidity();
31+
// Read temperature as Celsius
3132
float t = dht.readTemperature();
33+
// Read temperature as Fahrenheit
34+
float f = dht.readTemperature(true);
35+
// Compute heat index
36+
// Must send in temp in Fahrenheit!
37+
float hi = dht.computeHeatIndex(f, h);
3238

3339
// check if returns are valid, if they are NaN (not a number) then something went wrong!
3440
if (isnan(t) || isnan(h)) {
@@ -39,6 +45,12 @@ void loop() {
3945
Serial.print(" %\t");
4046
Serial.print("Temperature: ");
4147
Serial.print(t);
42-
Serial.println(" *C");
48+
Serial.print(" *C ");
49+
Serial.print(f);
50+
Serial.print(" *F\t");
51+
Serial.print("Heat index: ");
52+
Serial.print(hi);
53+
Serial.println(" *F");
54+
4355
}
4456
}

0 commit comments

Comments
 (0)