Support for dht22 grove temperature and humidity sensor

Dependencies:   DHT mbed

Fork of frdm_Grove_Temp-Humidity_Example by NXP

This repository supports Grove Temperature and Humidity Sensor Pro.

main.cpp

Committer:
Prashant_Dew
Date:
2016-08-17
Revision:
1:bc8bfc12d3c4
Parent:
0:9d72427a0730

File content as of revision 1:bc8bfc12d3c4:


#include "mbed.h"
#include "DHT.h"

DHT sensor(D4, 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.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);
        } else {
            printf("Error: %d\n", error);
        }
    }
}