![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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@2:17efe72364ea, 2017-01-07 (annotated)
- Committer:
- Sly_fox
- Date:
- Sat Jan 07 21:59:37 2017 +0000
- Revision:
- 2:17efe72364ea
- Parent:
- 0:c12c28a0f9e7
Changed to one decimal after deciml point as 1/100 of degrees do not realy make sense with these sensors.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 0:c12c28a0f9e7 | 1 | |
sam_grove | 0:c12c28a0f9e7 | 2 | #include "mbed.h" |
sam_grove | 0:c12c28a0f9e7 | 3 | #include "DHT.h" |
sam_grove | 0:c12c28a0f9e7 | 4 | |
Sly_fox | 2:17efe72364ea | 5 | DHT sensor(D7, DHT22); |
sam_grove | 0:c12c28a0f9e7 | 6 | |
sam_grove | 0:c12c28a0f9e7 | 7 | int main() |
sam_grove | 0:c12c28a0f9e7 | 8 | { |
sam_grove | 0:c12c28a0f9e7 | 9 | int error = 0; |
sam_grove | 0:c12c28a0f9e7 | 10 | float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f; |
sam_grove | 0:c12c28a0f9e7 | 11 | |
sam_grove | 0:c12c28a0f9e7 | 12 | while(1) { |
Sly_fox | 2:17efe72364ea | 13 | wait(2.0f); |
sam_grove | 0:c12c28a0f9e7 | 14 | error = sensor.readData(); |
sam_grove | 0:c12c28a0f9e7 | 15 | if (0 == error) { |
sam_grove | 0:c12c28a0f9e7 | 16 | c = sensor.ReadTemperature(CELCIUS); |
sam_grove | 0:c12c28a0f9e7 | 17 | f = sensor.ReadTemperature(FARENHEIT); |
sam_grove | 0:c12c28a0f9e7 | 18 | k = sensor.ReadTemperature(KELVIN); |
sam_grove | 0:c12c28a0f9e7 | 19 | h = sensor.ReadHumidity(); |
sam_grove | 0:c12c28a0f9e7 | 20 | dp = sensor.CalcdewPoint(c, h); |
sam_grove | 0:c12c28a0f9e7 | 21 | dpf = sensor.CalcdewPointFast(c, h); |
Sly_fox | 2:17efe72364ea | 22 | printf("Temperature in Kelvin: %4.1f, Celcius: %4.1f, Farenheit %4.1f\n", k, c, f); |
Sly_fox | 2:17efe72364ea | 23 | printf("Humidity is %4.1f, Dewpoint: %4.1f, Dewpoint fast: %4.1f\n", h, dp, dpf); |
Sly_fox | 2:17efe72364ea | 24 | printf("\n"); |
sam_grove | 0:c12c28a0f9e7 | 25 | } else { |
sam_grove | 0:c12c28a0f9e7 | 26 | printf("Error: %d\n", error); |
sam_grove | 0:c12c28a0f9e7 | 27 | } |
sam_grove | 0:c12c28a0f9e7 | 28 | } |
sam_grove | 0:c12c28a0f9e7 | 29 | } |