Simple library for the DHT11 temperature and humidity sensor. Forked from an existing Mbed DHT11 project.

Dependents:   UoY-DHT11-test

Simple DHT11 temperature and humidity library.

Example usage

#include "mbed.h"
#include "DHT11.h"

DHT11 dht(D8); // Change pin name here if required

main()
{
    printf("T:%d, H:%d\r\n", dht.readTemperature(), dht.readHumidity());
}

The sensor may be read as often as desired, but temperature and humidity values are cached and will only be updated if they are more than 2 seconds old. This is the underlying sensor update rate.

Please note that this project has been modified only enough to make it work for its intended purpose. Various parts of this project still need work, and the source code should not be seen as an example of best practice.

Revision:
7:50f5c8efd967
Parent:
6:257e2ab66d0f
Child:
8:160047ca45bf
diff -r 257e2ab66d0f -r 50f5c8efd967 DHT11.cpp
--- a/DHT11.cpp	Wed Sep 10 17:43:14 2014 +0000
+++ b/DHT11.cpp	Wed Sep 10 17:48:35 2014 +0000
@@ -43,8 +43,8 @@
     do {
         io = 0;
     } while (t.read_ms() < 18);
+    io = 1;
     io.input();
-    io = 1;
 
     // Waiting for the start of the response signal
     t.reset();
@@ -52,7 +52,6 @@
     do {
         if (t.read_us() > 100) {
             io.input();
-            io = 1;
             return NOT_PRESENT;
         }
     } while (io == 1);
@@ -63,7 +62,6 @@
     do {
         if (t.read_us() > 100) {
             io.input();
-            io = 1;
             return NOT_READY;
         }
     } while (io == 0);