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
main.cpp
- Committer:
- Sly_fox
- Date:
- 2017-01-07
- Revision:
- 3:cd7804120497
- Parent:
- 2:17efe72364ea
File content as of revision 3:cd7804120497:
#include "mbed.h" #include "DHT.h" DHT sensor(D7, DHT22); int main() { int error = 0; float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f; while(1) { wait(2.0f); error = sensor.readData(); if (0 == error) { c = sensor.ReadTemperature(CELCIUS); f = sensor.ReadTemperature(FARENHEIT); k = sensor.ReadTemperature(KELVIN); h = sensor.ReadHumidity(); dp = sensor.CalcdewPoint(c, h); dpf = sensor.CalcdewPointFast(c, h); 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); } } }