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.
Table of Contents
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.
Range | 0°C to 50°C (Temperature) 20% to 80% (Humidity) |
Accuracy | ±2°C (Temperature) ±5% (Humidity) |
Supply voltage | 3 to 5.5V |
Current consumption | Max. 2.5 mA |
Sampling time | 1 measurement per second |
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.
DHT11 | DHT22 (AM2302) | |
Cost | lower | low |
Voltage (supply and I/O) | 3 to 5.5V | 3 to 5.5V |
Max current | 2.5mA | 2.5mA |
Temperature range | 0-50°C | -40 to 80°C |
Temperature accuracy | ±2°C | ±0.5°C |
Humidity range | 20-80% | 0-100% |
Humidity accuracy | 5% | 2-5% |
Sampling rate | 1 Hz | 0.5 Hz |
Physical dimensions | 15.5mm x 12mm x 5.5mm | 15.1mm x 25mm x 7.7mm |
Pins | 4 pins with 0.1 inch spacing | 4 pins with 0.1 inch spacing |
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 and DHT22 Pin Configuration
DHT11 and DHT22 have only three connections: Vcc, GND, and Data. Pin 3 is not connected.

- 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 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

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
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
// Start Serial at baudrate 9600
Serial.begin(9600);
// Start DHT sensor
dht.begin();
}
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");
}
else
{
// Print out temp and humidity values
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print(" °C, ");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}
delay(5000);
}
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 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.

Do you want to learn more about sensors? Check out these articles below.
Interfacing Force Sensing Resistor (FSR) with Arduino
Interfacing HC-SR04 Ultrasonic Sensor With Arduino
Interfacing TTP223B Capacitive Touch Sensor with Arduino