Tutorial – DHT22 temperature module with Arduino

Tutorial – DHT22 temperature module with Arduino

In this tutorial we will explain how to use the DHT22 temperature module with Arduino. It is a module used to mesure humidity and temperature.

This module has a better accuracy then DHT11 (click to read the tutorial for DHT11), but of course it has an higher price, let’s see:

Accuracy for DHT22

  • Humidity: range 0-100%, error 2-5%
  • Temperature: range -40 to 80°C, error ±0.5°C

How the DHT22 works

This module measures both temperature and humidity. We can use it to make some very cool projects like measuring the temperature and humidity inside and outside a house!

It would be a very cool IoT project that we will make in the next days! Just follow us on instagram to read all the news! Or maybe you may click on the red bell in the right corner of the page! It enables the notifications so that you will receive a notification when we publish something new on the website!

Schematics for DHT22

Now we have to make a simple schematic for that Tutorial!

It is very simple, just follow do as follows:

From the left to the right

  • Arduino’s 5V -> “+” pin
  • digital pin4 -> out pin
  • Arduino’s GND -> “-” pin

Then we have to make a simple Sketch!

Sketch for DHT22

First of all you have to add the DHT.h library. If you don’t know how to add a library to the Arduino IDE, follow this guide -> How to add a Library to Arduino IDE.

#include <DHT.h>;

#define DHTpin 4     // which pin we're connected to
#define DHTtype DHT22   // DHT 22  (AM2302)
DHT dht(DHTpin, DHTtype); // Initialize DHT sensor

float hum;  //Stores humidity value
float temp; //Stores temperature value

void setup()
  delay(1000); //the module needs a while before working properly

void loop()
    //Read data and store it to variables hum and temp
    hum = dht.readHumidity();
    temp = dht.readTemperature();

    //Print temp and humidity values to serial monitor
    Serial.print("Humidity: ");
    Serial.print(" %, Temp: ");
    Serial.println(" Celsius");
    delay(2000); //Delay 2 sec.

I hope that after your read this tutorial on the DHT22 temperature module with Arduino you know how to use it in your projects!

Davide Busco

Davide Busco is an engineering student at Federico II University of Naples. He uses his passion and studies to create his projects. He loves be a maker and spread his knowledge. Moreover he has gained the second place in a national makers-tournament between Italian's Universities.

Leave a Reply

Your email address will not be published. Required fields are marked *