DHT11 and DHT22 Humidity Sensor Tutorial

This site has been great fun, but it has run its course, and it is time to move on. Please get what you want from the site before January 1, 2020. Some pages will move to another site but most will go away.

The DHT11 and DHT22 humidity sensors are widely available, and also very similar. The difference is in the speed. The DHT22 takes a minimum of 2 seconds between readings, the DHT11 can be read once every second. The price for the speed increase is reduced range and accuracy.

Reading the DHT11 more often will not improve its performance - the conversions take place in a fixed time determined by the model of sensor. Reading it more often just returns old data from the driver library. The DHT sensor library outputs the temperature and humidity in integral numbers. It is either 25°C or 26°C - it won't be 25.5°C

The DHT11/22 are simple to hook up. Vcc, Gnd, and one signal line. The pullup resistor is not an absolute requirement, but in noisy environments it will help prevent mis-reads. I didn't experience any without the pullup, but it never hurts to be cautious.


Cycle Time 1 Sec 2 Sec
Range 30%-80% 0-99.9%
Accuracy ±5% ±2%
Response Time 6-15 Sec <5 Sec
Range 0 to +50°C -40 to +80°C
Accuracy ±2°C ±1°C
Response Time 6-30 Sec <10 Sec


Keeping the sensors near the minimum or maximum of their range for extended periods of time will cause premature aging of the humidity sensor's polymer capacitor element.

The following code was adapted from an example which comes with the Adafruit DHT library (Not the unified version). Both the example and the library can be installed using the library installer "Sketch->Include Library->Library Manager".

#include <DHT.h>

#define SENSOR_PIN 2


void setup() {

void loop() {

  // Read the values from the sensor.
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
  float hi = dht.computeHeatIndex(f, h);

  Serial.print("Humidity: ");
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.print(" *C ");
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.println(" *F");


Only three wires connect the DHT to the Arduino. A resistor goes between the output and Vcc to pull up the line. The interface is slow and it takes a few passes to get the sensor to start sending valid data, so you may see a few lines of "Failed to read from DHT sensor!" before the temperature and humidity start to print.

Failed to read from DHT sensor!
Failed to read from DHT sensor!
Failed to read from DHT sensor!
Humidity: 36.00 %	Temperature: 23.00 *C 73.40 *F	Heat index: 72.13 *F
Humidity: 36.00 %	Temperature: 23.00 *C 73.40 *F	Heat index: 72.13 *F
Humidity: 36.00 %	Temperature: 23.00 *C 73.40 *F	Heat index: 72.13 *F


In the real world you want to keep a distance between sources of heat and humidity and the sensor. It should be in a place where external airflow can circulate past it.

As an Amazon Associate I earn from qualifying purchases.
Arduino Board Logo


Arduino-Board is the go-to source for information on many available Arduino and Arduino-like boards, tutorials and projects.

Help and Support


Stay updated

Sign up if you would like to receive our once monthly newsletter.