interface the DHT11/DHT22 temperature and humidity sensor with Arduino

What is a DHT11/DHT22 temperature and humidity sensor? How does it work?

A DHTT11/DHT22 is a type of sensor that is used for measuring the temperature and humidity of the surroundings. It consists of a capacitive type humidity sensor, whose capacitance changes depending upon the moisture present in the air, and a thermistor type temperature sensor, whose resistance changes depending upon the temperature. An 8-bit microcontroller is also present in the sensor that will take capacitance and resistance value from both the sensors and outputs serial data that consists of both humidity and temperature values. These temperature and humidity values can be further read by another microcontroller like Arduino UNO by interfacing the sensor with it.  You can either use pre-built libraries or you can write your own code for interfacing by referring to the datasheet. Here, we will discuss how to use the pre-built library to receive data from the sensor. This sensor comes in two variants one is DHT11 and another is DHT22. The DTH22 is way better than the DHT11 in terms of many aspects. The features of both the sensors are given below.

Features

DHT11

DHT22

Operating voltage

3.3-5 V DC

3.3-5 V DC

Current consumption

2.5mA

2.5mA

Temperature range

0-50/ ±2°C 

-40-125/ ±0.5°C

Humidity Range

20-80/ ±5%

0-100/ ±2-5%

Sampling Rate

1Hz(One reading every one second)

0.5Hz(One reading every two seconds)

Pin diagram of the DHT11/DHT22 temperature and humidity sensor

Both DHTT11 and DHT22 have two variants.
The first variant is a module that consists of a power status LED and a pull of resistor that is necessary for receiving data from the sensor. See figure 1. This variant has only three pins.

The second variant is only the sensor. See figure 2. In order to receive data from the sensor, you have to connect an external pull-up resistor. This variant has four pins.

DHT11 and DHT22 pin diagram
DHT11 and DHT22 pin configuration

The function of each pin of the sensor

  • The VCC pin is used to connect 3-3-5V DC to the sensor.
  • The GND pin is used to connect GND to the sensor
  • The Data pin is used to get data from the sensor.
  • The NC pin is not used for any purpose, you have to leave it as it is.

Features of DHT11 Temperature and Humidity sensor 

  • The operating voltage is between 3 to 5.5 volts.
  • The operating current is <2.5mA
  • The accuracy for measuring temperature is ±2°C.
  • The accuracy for measuring humidity is ±5%.
  • It can transmit the signal up to 20m. 

Electronics components needed

  • Arduino UNO
  • DHT11/DHT22 sensor
  • One 10K ohm resistor(Needed when you are not using the module)
  • Breadboard
  • Jumper wires

Pin connections of the DHT11 Temperature and Humidity sensor with Arduino UNO

  • Connect the VCC pin of the sensor to the 5v pin of the Arduino UNO.
  • Connect the GND pin of the sensor to the GND pin of the Arduino UNO.
  • Connect the Data pin of the sensor to the D2 pin of the Arduino UNO
  • Jumper wires

Circuit diagram of DHT11/DHT22 temperature and humidity sensor with Arduino UNO

DHT11 Arduino circuit diagram
DHT22 Arduino circuit diagram
DHT22 Arduino circuit diagram
DHT22 Arduino circuit diagram

Click to download DHT11 Library:  https://github.com/adafruit/DHT-sensor-library/blob/master/DHT.h
Please install this library in Arduino IDE otherwise you will get an error.

Arduino code for the DHT11 sensor

#include"DHT.h"// Download this library from the link given below
 
#define DHTPIN 2// Define pin of the DHT11 sensor data pin
 
#define DHTTYPE DHT11// Define the type of the sensor. for DHT22 type DHT22 instead of DHT11
 
DHT dht(DHTPIN, DHTTYPE);// Create an object of type DHT to access all the functions of the library
 
void setup(){
 
  Serial.begin(9600);// Set baud rate for serial communication
 
  dht.begin();// Initiate DHT sensor
 
}
 
void loop(){
 
 int hum = dht.readHumidity();//Get humidity data using readHumidity() function
 
 int temp = dht.readTemperature();//Get temperature data using readTemperature() function
 
    Serial.print("Humidity: ");
 
    Serial.println(hum);//Print humidity on the serial monitor
 
    Serial.print("Temperature: ");
 
    Serial.print(temp);//Print temperature on the serial monitor
 
    Serial.println(" *C");
 
  }
 
}

Output results

DHT11 circuit diagram
DHT11/DHT22 Arduino Code

Leave a Reply