Skip to content

DHT11 Humidity and Temperature Sensor

In this tutorial you will learn how to use a DHT11 Temperature and Humidity Sensor with the Arduino, what is DHT11, difference between DHT11 and DHT22, DHT11 circuit diagram with the Arduino, and how to write Arduino code to read DHT11 Temperature and Humidity. Finally, we will introduce the Elegoo DHT11 module.

What is DHT11 ?

The DHT11 sensor is low-cost Temperature and Humidity sensor that is ideal for hobbyists and prototyping applications. The DHT11 temperature sensor range: 0 – 50°C (±2°C) and DHT11 humidity sensor range: 20-80% (±5%). Its Supply voltage: 3 to 5.5V. DHT11 sensor uses a OneWire protocol.  It integrates a thermistor and a capacitive humidity sensor. An integrated ADC converter converts the measured values into a digital signal, which is then output via the OneWire interface.

Range0°C to 50°C (Temperature) 20% to 80% (Humidity)
Accuracy±2°C (Temperature) ±5% (Humidity)
Supply voltage3 to 5.5V
Current consumptionMax. 2.5 mA
Sampling time1 measurement per second
DHT11 Specifications

DHT11 vs DHT22 Specifications

Both DHT11 and DHT22 have the same pin configuration but have different characteristics. The comparison is shown below. In summary, the DHT22 a little more accurate have a slightly larger temperature and humidity range.

 DHT11DHT22 (AM2302)
Voltage (supply and I/O)3 to 5.5V3 to 5.5V
Max current2.5mA2.5mA
Temperature range0-50°C-40 to 80°C
Temperature accuracy±2°C±0.5°C
Humidity range20-80%0-100%
Humidity accuracy5%2-5%
Sampling rate1 Hz0.5 Hz
Physical dimensions15.5mm x 12mm x 5.5mm15.1mm x 25mm x 7.7mm
Pins4 pins with 0.1 inch spacing4 pins with 0.1 inch spacing
DHT11 and DHT22 Specifications

DHT11 Sensor Application

DHT11 is usually used in Weather Stations, HVAC, Dehumidifier, data loggers, humidity regulators, Home Appliances, and Consumer Electronics.

DHT11 sensor circuit diagram

The circuit diagram below shows DHT sensor Arduino circuit. Connect Pin 1 directly to Supply (3.3V or 5V), pin 4 to GND, and Pin 2 to the microcontroller pin with pull-up resistor to the supply voltage.

DHT11 sensor Arduino circuit. Source: Elegoo Inc.

DHT11 and DHT22 Pin Configuration

DHT11 and DHT22 have only three connections: Vcc, GND, and Data. Pin 3 is not connected.

DHT11 Pin configuration
  • Pin 1: Vcc
  • Pin 2: Data
  • Pin 3: NC
  • Pin 4: GND

Parts list (DHT11 Arduino)

The parts required for this tutorial are:

  • 1 Arduino board
  • 1 Breadboard
  • 1 Sensor DHT11 or DHT22
  • 1 Resistor 10k ohm
  • Connecting wires

DHT11 Fritzing Circuit

The figure below shows the DHT11 sensor interfacing with arduino. The DHT11 data pin is connected to the arduino digital pin 2.

DHT11 fritzing circuit

DHT11 Arduino Code

First install DHT sensor library:

In the Arduino IDE, go to Sketch->Include Library->Manage Libraries…

Type DHT11 in the search tab then go to DHT sensor library and click Install

DHT sensor library

After installing DHT sensor library, you should include the header file DHT.h in your program. Then define the Arduino pin for DHT sensor (here it’s pin 2), then select the DHT type (here DHT11) and define dht object. See the DHT11 temperature and humidity sensor Arduino code below.

#include "DHT.h"

// Define DHT pin
#define DHTPIN 2
// DHT11 selected
#define DHTTYPE DHT11 // Other possibilities DHT21, DHT22 

// Define DHT object

void setup()
  // Start Serial at baudrate 9600
  // Start DHT sensor

void loop()
  // Read temperature sensor
  float temp = dht.readTemperature();
  // Read humidity sensor
  float humidity = dht.readHumidity();
  /* Are temp and humidity values valid numbers? */
  if (isnan(temp) || isnan(humidity))
    Serial.println("Failed to read from DHT11");
    // Print out  temp and humidity values
    Serial.print("Temperature: ");
    Serial.print(" °C, ");
    Serial.print("Humidity: ");
    Serial.println(" %");

In the setup routine, the serial interface is configured to print out the measurement on the serial monitor and the DHT sensor is started.

In the main program, the measured values for humidity and temperature are now read in and assigned to the variables humidity and temp. The program then checks whether a valid numerical value has been measured for humidity and temperature. If both measured values are valid, they are printed out on the serial monitor, otherwise an error message is printed out.

DHT11 Serial Monitor

The code shown above remains the same. After wiring the Elegoo DHT11 Sensor with the Arduino. Click UPLOAD to upload the program shown above then open the serial monitor, you can see the data as below: (The temperature is around 23°C the humidity is 59.00 %)

DHT11 serial monitor

Elegoo DHT11 Sensor Module

The Elegoo DHT11 Module integrates the built-in 10 Kohm pull-up resistor. See figure below.

Elegoo DHT11 sensor module

Elegoo DHT11 Pin configuration

The mark S denotes the signal (pin 3).

  • Pin 1: GND
  • Pin 2: Vcc (3.3V or 5V)
  • Pin 3: Output

Elegoo DHT11 Arduino Circuit Diagram

The circuit diagram below shows the DHT sensor Arduino circuit. Since the pull-up resistor is already integrated into the module, connct the data pin directly to the arduino pin 2.

DHT sensor Arduino circuit. Source: Elegoo Inc.
error: Content is protected !!