File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,20 @@ float DHT::readHumidity(void) {
74
74
return NAN;
75
75
}
76
76
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
+
77
91
78
92
boolean DHT::read (void ) {
79
93
uint8_t laststate = HIGH;
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ class DHT {
33
33
void begin (void );
34
34
float readTemperature (bool S=false );
35
35
float convertCtoF (float );
36
+ float computeHeatIndex (float tempFahrenheit, float percentHumidity);
36
37
float readHumidity (void );
37
38
38
39
};
Original file line number Diff line number Diff line change @@ -28,7 +28,13 @@ void loop() {
28
28
// Reading temperature or humidity takes about 250 milliseconds!
29
29
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
30
30
float h = dht.readHumidity ();
31
+ // Read temperature as Celsius
31
32
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);
32
38
33
39
// check if returns are valid, if they are NaN (not a number) then something went wrong!
34
40
if (isnan (t) || isnan (h)) {
@@ -39,6 +45,12 @@ void loop() {
39
45
Serial.print (" %\t " );
40
46
Serial.print (" Temperature: " );
41
47
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
+
43
55
}
44
56
}
You can’t perform that action at this time.
0 commit comments