mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
Update example to show temp in Fahrenheit and add computeHeatIndex function to resolve issue #9.
This commit is contained in:
parent
633eb08654
commit
ffac2f15b7
14
DHT.cpp
14
DHT.cpp
@ -74,6 +74,20 @@ float DHT::readHumidity(void) {
|
|||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float DHT::computeHeatIndex(float tempFahrenheit, float percentHumidity) {
|
||||||
|
// Adapted from equation at: https://github.com/adafruit/DHT-sensor-library/issues/9 and
|
||||||
|
// Wikipedia: http://en.wikipedia.org/wiki/Heat_index
|
||||||
|
return -42.379 +
|
||||||
|
2.04901523 * tempFahrenheit +
|
||||||
|
10.14333127 * percentHumidity +
|
||||||
|
-0.22475541 * tempFahrenheit*percentHumidity +
|
||||||
|
-0.00683783 * pow(tempFahrenheit, 2) +
|
||||||
|
-0.05481717 * pow(percentHumidity, 2) +
|
||||||
|
0.00122874 * pow(tempFahrenheit, 2) * percentHumidity +
|
||||||
|
0.00085282 * tempFahrenheit*pow(percentHumidity, 2) +
|
||||||
|
-0.00000199 * pow(tempFahrenheit, 2) * pow(percentHumidity, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean DHT::read(void) {
|
boolean DHT::read(void) {
|
||||||
uint8_t laststate = HIGH;
|
uint8_t laststate = HIGH;
|
||||||
|
1
DHT.h
1
DHT.h
@ -33,6 +33,7 @@ class DHT {
|
|||||||
void begin(void);
|
void begin(void);
|
||||||
float readTemperature(bool S=false);
|
float readTemperature(bool S=false);
|
||||||
float convertCtoF(float);
|
float convertCtoF(float);
|
||||||
|
float computeHeatIndex(float tempFahrenheit, float percentHumidity);
|
||||||
float readHumidity(void);
|
float readHumidity(void);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -28,7 +28,13 @@ void loop() {
|
|||||||
// Reading temperature or humidity takes about 250 milliseconds!
|
// Reading temperature or humidity takes about 250 milliseconds!
|
||||||
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
|
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
|
||||||
float h = dht.readHumidity();
|
float h = dht.readHumidity();
|
||||||
|
// Read temperature as Celsius
|
||||||
float t = dht.readTemperature();
|
float t = dht.readTemperature();
|
||||||
|
// Read temperature as Fahrenheit
|
||||||
|
float f = dht.readTemperature(true);
|
||||||
|
// Compute heat index
|
||||||
|
// Must send in temp in Fahrenheit!
|
||||||
|
float hi = dht.computeHeatIndex(f, h);
|
||||||
|
|
||||||
// check if returns are valid, if they are NaN (not a number) then something went wrong!
|
// check if returns are valid, if they are NaN (not a number) then something went wrong!
|
||||||
if (isnan(t) || isnan(h)) {
|
if (isnan(t) || isnan(h)) {
|
||||||
@ -39,6 +45,12 @@ void loop() {
|
|||||||
Serial.print(" %\t");
|
Serial.print(" %\t");
|
||||||
Serial.print("Temperature: ");
|
Serial.print("Temperature: ");
|
||||||
Serial.print(t);
|
Serial.print(t);
|
||||||
Serial.println(" *C");
|
Serial.print(" *C ");
|
||||||
|
Serial.print(f);
|
||||||
|
Serial.print(" *F\t");
|
||||||
|
Serial.print("Heat index: ");
|
||||||
|
Serial.print(hi);
|
||||||
|
Serial.println(" *F");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user