A library for the use of DHT11, a temperature and humidity sensor

Dependents:   HTTP_SERVER2 lightweight-weather-station

Embed: (wiki syntax)

« Back to documentation index

DHT11 Class Reference

DHT11 Class Reference

Example: More...

#include <DHT11.h>

Public Member Functions

 DHT11 (PinName pin)
 Create a DHT11 interface.
int readData (void)
 Reading the data from the DHT11.
int readHumidity (void)
 Reading the humidity from the data.
int readTemperature (void)
 Reading the temperature from the data.

Detailed Description

Example:

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

 DHT11 d(PTD1);

 main()
 {
     int s;
     s = d.readData();
     if (s != DHT11::OK) {
         printf("Error!\r\n");
     }
     else {
         printf("T:%d, H:%d\r\n", d.readTemperature(), d.readHumidity());
     }
 }

Definition at line 44 of file DHT11.h.


Constructor & Destructor Documentation

DHT11 ( PinName  pin )

Create a DHT11 interface.

Parameters:
pin1-wire-like serial I/O port of DHT11

Definition at line 22 of file DHT11.cpp.


Member Function Documentation

int readData ( void   )

Reading the data from the DHT11.

Returns:
Error code 0: OK. 1: Reading the data too often. 2: 1-wire bus is busy. 3: DHT11 does not respond. 4: DHT11 is not ready. 5: Checksum is incorrect. 6: Timeout.

Definition at line 39 of file DHT11.cpp.

int readHumidity ( void   )

Reading the humidity from the data.

Returns:
Humidity in %, regardless of the error from readData()

Definition at line 123 of file DHT11.cpp.

int readTemperature ( void   )

Reading the temperature from the data.

Returns:
Temperature in Celcius, regardless of the error from readData()

Definition at line 129 of file DHT11.cpp.