How to Set Up the DHT11 Humidity Sensor on an Arduino


The DHT11 humidity and temperature sensor is is capable of measuring relative humidity between 20 and 90% RH within the operating temperature range of 0 to 50°C, with an accuracy of ±5% RH. Additionally, temperature is measured in the range of 0 to 50°C, with an accuracy of ±2°C. Both values are returned with 8-bit resolution.



The signaling used by the DHT sensor is similar to the 1-Wire protocol, but the response times differ. Additionally, there is no device serial number support.
The DHT11 sensor also requires a power supply. In contrast, the signal line itself powers most 1-Wire peripherals. The datasheet states that the DHT11 can be powered by a range of voltages, from 3 V to 5.5 V. The device draws between 0.5 mA and 2.5 mA. Its standby current is stated as 100 mA to 150 mA, for those concerned about battery consumption.
The sensor speaks only when spoken to by the master. The master must first make a request on the bus and then wait for the sensor to respond. The DHT sensor responds with 40 bits of information, 8 of which are a checksum.
The overall signal protocol works like this.
  • The line idles high because of the pull-up resistor.
  • The master pulls the line low for at least 18 ms to signal a read request and then releases the bus, allowing the line to return to a high state.
  • After a pause of about 20 to 40 ms, the sensor responds by bringing the line low for 80 ms and then allows the line to return high for a further 80 ms. This signals its intention to return data.
  • Forty bits of information are then written out to the bus: each bit starting with a 50 ms low followed by 26 to 28 ms of high to indicate a 0 bit, and 70 ms of high to indicate a 1 bit.
  • The transmission ends with the sensor bringing the line low one more time for 50 ms.
  • The sensor releases the bus, allowing the line to return to a high idle state.
The DHT11 humidity and temperature sensor measures relative humidity (RH) and temperature. Relative humidity is the ratio of water vapor in air versus the saturation point of water vapor in air. The saturation point of water vapor in air changes with temperature. Cold air can hold less water vapor before it is saturated, and hot air can hold more water vapor before it is saturated. The formula for relative humidity is as follows.

  • Relative Humidity = (dW / dS) x 100%
  • dW = density of water vapor
  • dS = density of water vapor at saturation

Basically, relative humidity is the amount of water in the air compared to the amount of water that air can hold before condensation occurs. It’s expressed as a percentage. For example, at 100% RH condensation (or rain) occurs, and at 0% RH, the air is completely dry.
Here is library for DHT11, wiring diagram, and sketch (source code) for serial monitor.



#include <dht.h>

dht DHT;

#define DHT11_PIN 2

void setup()

{
  Serial.begin(9600);
}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  delay(1000);
}