Example for DHT22 / AM2302 DHT11 and similar sensors. Now with value behind decimal point for DHT22 and comment on the calculation for temp and humidity of DHT22
Fork of Seeed_Grove_Temp_Humidity_Example by
Diff: main.cpp
- Revision:
- 2:17efe72364ea
- Parent:
- 0:c12c28a0f9e7
--- a/main.cpp Tue Mar 10 21:33:31 2015 +0000 +++ b/main.cpp Sat Jan 07 21:59:37 2017 +0000 @@ -2,7 +2,7 @@ #include "mbed.h" #include "DHT.h" -DHT sensor(D4, DHT11); +DHT sensor(D7, DHT22); int main() { @@ -10,7 +10,7 @@ float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f; while(1) { - wait(2.0f); + wait(2.0f); error = sensor.readData(); if (0 == error) { c = sensor.ReadTemperature(CELCIUS); @@ -19,8 +19,9 @@ h = sensor.ReadHumidity(); dp = sensor.CalcdewPoint(c, h); dpf = sensor.CalcdewPointFast(c, h); - printf("Temperature in Kelvin: %4.2f, Celcius: %4.2f, Farenheit %4.2f\n", k, c, f); - printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\n", h, dp, dpf); + printf("Temperature in Kelvin: %4.1f, Celcius: %4.1f, Farenheit %4.1f\n", k, c, f); + printf("Humidity is %4.1f, Dewpoint: %4.1f, Dewpoint fast: %4.1f\n", h, dp, dpf); + printf("\n"); } else { printf("Error: %d\n", error); }