DHT11 Sensor Interfacing with ARM MBED

Overview of DHT11 Sensor

DHT11 Sensor

 

  • DHT11 sensor measures and provides humidity and temperature values serially over a single wire.
  • It can measure the relative humidity in percentage (20 to 90% RH) and temperature in degree Celsius in the range of 0 to 50°C.
  • It has 4 pins; one of which is used for data communication in serial form.
  • Pulses of different TON and TOFF are decoded as logic 1 or logic 0 or start pulse or end of the frame.

For more information about the DHT11 sensor and how to use it, refer the topic DHT11 sensor in the sensors and modules topic.

 

Connection Diagram of DHT11 with ARM MBED (LPC1768)

Interfacing DHT11 Sensor with ARM MBED

 

Reda Temperature and Humidity using DHT11 and ARM MBED (LPC1768)

Reading temperature and humidity from DHT11 sensor.

Here, we will be using DHT11 library by seed studio from mbed. To use this library, we have to import or download DHT11 library developed by SEEED Studio.

 

DHT11 Code for ARM MBED (LPC1768)

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

DHT sensor(p5, DHT11);

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);
        }
    }
}

 

Output of DHT11 in the serial window


Components Used

ARM mbed 1768 LPC1768 Board
ARM mbed 1768 Board
1
DHT11
DHT11 is a single wire digital humidity and temperature sensor, which gives relative humidity in percentage and temperature in degree Celsius.
1

Downloads

Seeed_Grove_Temp_Humidity_Example_uvision5_lpc1768 Download
Ad