Simple library for the DHT11 temperature and humidity sensor. Forked from an existing Mbed DHT11 project.
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.
Diff: DHT11.h
- Revision:
- 5:da586c935e88
- Parent:
- 4:48798b126d93
- Child:
- 9:056d1e9b428c
--- a/DHT11.h Wed Sep 10 17:18:28 2014 +0000 +++ b/DHT11.h Wed Sep 10 17:35:27 2014 +0000 @@ -44,17 +44,19 @@ * 3: DHT11 does not respond. * 4: DHT11 is not ready. * 5: Checksum is incorrect. - * 6: Timeout + * 6: Timeout. */ int readData(void); /** Reading the humidity from the data - * @return Humidity in % if readData() returns no error. Otherwise, returns 0xffffffff. + * @return Humidity in % if readData() returns no error. + * Otherwise, returns 0xffffffff. */ int readHumidity(void); /** Reading the temperature from the data - * @return Temperature in Celcius if readData() returns no error. Otherwise, returns 0xffffffff. + * @return Temperature in Celcius if readData() returns no error. + * Otherwise, returns 0xffffffff. */ int readTemperature(void); @@ -69,7 +71,6 @@ }; private: - PinName _pin; DigitalInOut io; InterruptIn io_irq; Timer t;