DHT11 example for WIZwiki-W7500

Dependencies:   DHT mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "DHT.h"
00003 
00004 #define   DHT_DATA_PIN  D4
00005  
00006 DHT sensor(DHT_DATA_PIN, DHT11);                    //DHT(PinName pin, eType DHTtype)
00007  
00008 int main()
00009 {
00010     int error = 0;
00011     float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f;
00012  
00013     while(1) 
00014     {
00015         wait(2.0f);                                 //wait 2 second
00016         error = sensor.readData();                  //read error value
00017         if (error == 0)                             //case: no error 
00018         {
00019             c   = sensor.ReadTemperature(CELCIUS);
00020             f   = sensor.ReadTemperature(FARENHEIT);
00021             k   = sensor.ReadTemperature(KELVIN);
00022             h   = sensor.ReadHumidity();
00023             dp  = sensor.CalcdewPoint(c, h);
00024             dpf = sensor.CalcdewPointFast(c, h);
00025             printf("Temperature in Kelvin: %4.2f, Celcius: %4.2f, Farenheit %4.2f\n", k, c, f);
00026             printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\n", h, dp, dpf);
00027         } 
00028         else                                        //case: error
00029         {
00030             printf("Error: %d\n", error);
00031         }
00032     }
00033 }