-
-
Save donnib/6ed4d2bfd5a5e4047202 to your computer and use it in GitHub Desktop.
DHT11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <user_config.h> | |
#include <SmingCore/SmingCore.h> | |
#include <Libraries/DHT/DHT.h> | |
#define WORK_PIN 14 // GPIO14 | |
DHT dht(WORK_PIN,DHT11); | |
void displayComfort(); | |
void readSensor(); | |
Timer procTimer; | |
void init() | |
{ | |
Serial.begin(SERIAL_BAUD_RATE); // 115200 by default | |
Serial.systemDebugOutput(true); // Allow debug output to serial | |
Serial.println("\t\t DHT improved lib"); | |
Serial.println("wait 1 second for the sensor to boot up"); | |
//disable watchdog | |
WDT.enable(false); | |
//wait for sensor startup | |
delay(2000); | |
dht.begin(); | |
// Start reading loop | |
procTimer.initializeMs(2000, readSensor).start(); | |
} | |
void readSensor() | |
{ | |
Serial.println("\t\t Reading from sensor"); | |
WDT.alive(); | |
/* improved reading method */ | |
Serial.print("\nRead using new API methods\n"); | |
TempAndHumidity th; | |
if(dht.readTempAndHumidity(th)) | |
{ | |
Serial.print("\tHumidity: "); | |
Serial.print(th.humid); | |
Serial.print("% Temperature: "); | |
Serial.print(th.temp); | |
Serial.print(" *C\n"); | |
} | |
else | |
{ | |
Serial.print("Failed to read from DHT: "); | |
Serial.print(dht.getLastError()); | |
} | |
/* other goodies */ | |
/* | |
* Heatindex is the percieved temperature taking humidity into account | |
* More: https://en.wikipedia.org/wiki/Heat_index | |
* */ | |
Serial.print("Heatindex: "); | |
Serial.print(dht.getHeatIndex()); | |
Serial.print("*C\n"); | |
/* | |
* Dewpoint is the temperature where condensation starts. | |
* Water vapors will start condensing on an object having this temperature or below. | |
* More: https://en.wikipedia.org/wiki/Dew_point | |
* */ | |
Serial.printf("Dewpoint: "); | |
Serial.print(dht.getDewPoint(DEW_ACCURATE_FAST)); | |
Serial.print("*C\n"); | |
/* | |
* Determine thermal comfort according to http://epb.apogee.net/res/refcomf.asp | |
* */ | |
displayComfort(); | |
} | |
void displayComfort() | |
{ | |
ComfortState cf; | |
Serial.print("Comfort is at "); | |
Serial.print(dht.getComfortRatio(cf)); | |
Serial.print(" percent, ("); | |
switch(cf) | |
{ | |
case Comfort_OK: | |
Serial.print("OK"); | |
break; | |
case Comfort_TooHot: | |
Serial.print("Too Hot"); | |
break; | |
case Comfort_TooCold: | |
Serial.print("Too Cold"); | |
break; | |
case Comfort_TooDry: | |
Serial.print("Too Dry"); | |
break; | |
case Comfort_TooHumid: | |
Serial.print("Too Humid"); | |
break; | |
case Comfort_HotAndHumid: | |
Serial.print("Hot And Humid"); | |
break; | |
case Comfort_HotAndDry: | |
Serial.print("Hot And Dry"); | |
break; | |
case Comfort_ColdAndHumid: | |
Serial.print("Cold And Humid"); | |
break; | |
case Comfort_ColdAndDry: | |
Serial.print("Cold And Dry"); | |
break; | |
default: | |
Serial.print("Unknown:"); | |
Serial.print(cf); | |
break; | |
} | |
Serial.print(")\n"); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 32.00% Temperature: 26.00 *C | |
Heatindex: 25.92*C | |
Dewpoint: 8.05*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 42.00% Temperature: 26.00 *C | |
Heatindex: 26.28*C | |
Dewpoint: 12.12*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 32.00% Temperature: 26.00 *C | |
Heatindex: 25.92*C | |
Dewpoint: 8.05*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 50.00% Temperature: 26.00 *C | |
Heatindex: 26.57*C | |
Dewpoint: 14.79*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 54.00% Temperature: 26.00 *C | |
Heatindex: 26.71*C | |
Dewpoint: 15.99*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 32.00% Temperature: 26.00 *C | |
Heatindex: 25.92*C | |
Dewpoint: 8.05*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 39.00% Temperature: 26.00 *C | |
Heatindex: 26.17*C | |
Dewpoint: 11.00*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 52.00% Temperature: 26.00 *C | |
Heatindex: 26.64*C | |
Dewpoint: 15.40*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 0.00% Temperature: 0.00 *C | |
Heatindex: -8.78*C | |
Dewpoint: nan*C | |
Comfort is at 0.00 percent, (Cold And Dry) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 37.00% Temperature: 26.00 *C | |
Heatindex: 26.10*C | |
Dewpoint: 10.21*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 34.00% Temperature: 26.00 *C | |
Heatindex: 25.99*C | |
Dewpoint: 8.95*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 36.00% Temperature: 26.00 *C | |
Heatindex: 26.06*C | |
Dewpoint: 9.80*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 36.00% Temperature: 26.00 *C | |
Heatindex: 26.06*C | |
Dewpoint: 9.80*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 38.00% Temperature: 26.00 *C | |
Heatindex: 26.13*C | |
Dewpoint: 10.61*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 31.00% Temperature: 26.00 *C | |
Heatindex: 25.88*C | |
Dewpoint: 7.59*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 34.00% Temperature: 26.00 *C | |
Heatindex: 25.99*C | |
Dewpoint: 8.95*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 38.00% Temperature: 26.00 *C | |
Heatindex: 26.13*C | |
Dewpoint: 10.61*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 31.00% Temperature: 26.00 *C | |
Heatindex: 25.88*C | |
Dewpoint: 7.59*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 37.00% Temperature: 27.00 *C | |
Heatindex: 26.72*C | |
Dewpoint: 11.09*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 39.00% Temperature: 26.00 *C | |
Heatindex: 26.17*C | |
Dewpoint: 11.00*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 32.00% Temperature: 26.00 *C | |
Heatindex: 25.92*C | |
Dewpoint: 8.05*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) | |
.. Reading from sensor | |
Read using new API methods | |
.Humidity: 31.00% Temperature: 26.00 *C | |
Heatindex: 25.88*C | |
Dewpoint: 7.59*C | |
Comfort is at 100.00 percent, (OK) | |
.. Reading from sensor | |
Read using new API methods | |
Failed to read from DHT: 2Heatindex: nan*C | |
Dewpoint: nan*C | |
Comfort is at nan percent, (Unknown:1073674592) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment