The DHT22 – temperature and humidity sensor

Introduction

The DTH22 module is a relative cheap(2-3$) temperature and humidity sensor. This article describes how to set it up on Arduino nano, esp8266 and raspberry pi. Code examples for each are also available.

Table 1: Components used
Component Quantity Link (Ebay affiliate link)
DHT22 – temperature/humidity sensor 1 DHT22/AM2302 Digital Temperature And Humidity Sensor
NodeMcu Lua dev board(esp8266) 1
Raspberry pi 3 1
Arduino Nano 1
Resistor 10kohm 1
Jump wires 9
Breadboard half+ 1

The sensor

The sensor operates both on 3.3V and 5V and only requires one external component, a pull up resistor, making it very versatile and easy to use! However measuring faster than every two seconds is not possible. For a comprehensive list of specifications, see table below:

Specifications DTH22 Humidity Temperature
Voltage supply 3.3-6V DC
Output signal Digital signal via single-bus (yellow wire)
Operating range 0% – 100% RH (relative humidity) -40°C – 80°C (-40.0°F – 176.0°F)
Accuracy ± 2% (Max ± 5%) ± 0.5°C (0.9°F)
Resolution 0.1% 0.1°C (0.18°F)
Sensing period 2s on average
Dimensions small size 14*18*5.5mm – big size 22*28*5mm

DHT22 pin out

The pinout for the sensor below. Note that one pin is not used and hence left unconnected. (third pin from the left)

Pinout

What to expect

To give you a feeling of the resolution and data extracted from a DHT22 I’ve included two graphs of the real data collected from my DHT22 sensor, bought on ebay (link in component table). The data was collected in the morning, can you guess when I woke up? 🙂

Relative humidity(%) y axis, time(seconds) x axis
Temperature(°C) y axis, time(seconds) x axis

Hook-up and code examples

All code examples displayed below are also available at the Codeterrific GitHub repo.

Codeterrific GitHub repository

Node mcu(ESP8266)

NodeMCU set up
Programming the NodeMCU

Raspberry Pi

Raspberry Pi 3/2 set up

Install Adafruit DHT library

Run the script

Arduino Nano

Arduino nano set up

Install DHT via Library Manager