How to Use DHT-22 Sensor - Arduino Tutorial

About: Arduino Tutorials by Codebender.cc Team

The DHT-22 (also named as AM2302) is a digital-output relative humidity and temperature sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin.

In this tutorial you will learn how to use this sensor with Arduino uno. The room temperature & humidity will be printed to serial monitor.

So, let's get started!

Step 1: About the DHT-22 Sensor

The DHT22 is a basic, low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin (no analog input pins needed).

Connections are simple, the first pin on the left to 3-5V power, the second pin to your data input pin and the right most pin to ground.

Technical details:

  • Power: 3-5V
  • Max Current: 2.5mA
  • Humidity: 0-100%, 2-5% accuracy
  • Temperature: -40 to 80°C, ±0.5°C accuracy

Step 2: What You Will Need

For this tutorial you will need:

  • Arduino uno
  • Breadboard
  • DHT-22

Step 3: The Circuit

The connections are pretty easy, see the image above with the breadboard circuit schematic.

Step 4: The Code

Here's the code, embedded using codebender!

Try downloading the codebender plugin and clicking on the "Run on Arduino" button to program your Arduino board with this sketch. Below you will also find codebender serial monitor, press connect button to start receiving data from sensor.


Step 5: Well Done!

You have successfully completed one more Arduino "How to" tutorial and you learned how to use the DHT-22 sensor.

I hope you liked this, let me know in the comments.

There will be more of them, so make sure to click Follow button!

3 People Made This Project!

Recommendations

  • Make it Glow Contest 2018

    Make it Glow Contest 2018
  • Optics Contest

    Optics Contest
  • Plastics Contest

    Plastics Contest

26 Discussions

0
None
jroachsr

Question 6 months ago on Step 2

I copied & pasted your code but get an error "exit status 1" error compiling for board Arduino/Genuine UNO. However if I use the online uploader it indicates it up loaded successfully. I want to use this program with a LCD but if I can't compile this portion of the code I cannot add to it, any suggestions?

0
None
sahanl2hornerj99

Reply 1 year ago

as a pullup on the data line and 5v

0
None
JayM83

2 years ago

Hi!, I am Jay and want to ask about the problem which i faced. I connected everything perfectly, codes were also perfect but then i uploaded the code onto the Intel Galileo Gen2 board and found out that no humidity and temperature is measured perfectly through serial monitor. it says " Humidity = 0% Temperature = 0.00C". Please help me out.

1 reply
0
None
sahanl2JayM83

Reply 1 year ago

is ur sensor connected to digital pin 2

0
None
charliescarface

1 year ago

Can this project be used in conjunction with a WeMo switch to turn on/off a furnace based on the humidity of that space?

1 reply
0
None
sahanl2charliescarface

Reply 1 year ago

use a relay board and the if function. As long as ur furnace has some sort of electric starting and stopping mechanism (electric heating system).

Otherwise you will have to think of a handy mech to turn on and off the furnace mechanically and electrically.

if (humidity > 60)

{

digitalWrite(relayPin, HIGH);

}

else
{

digitalWrite(relayPin, LOW);

}

0
None
ChandruS6

1 year ago

But Great Project I already made it!

0
None
ChandruS6

1 year ago

Where I should get the DHT22.h Library?

❓❓❓❓❓❓❓

0
None
banjabi1

1 year ago

probably need to add these lines:
#include <DHT.h>
#include <DHT_U.h>
#include <Adafruit_Sensor.h>

and first install Adafruit Dht22 and somekind of Unified Sensor library from the library manager

1 reply
0
None
banjabi1banjabi1

Reply 1 year ago

and the other weird thing that i noticed, lol...:
you cant have any backup copies of the same sketch file in the same folder, otherwise you get a redefinition error?:o

0
None
soardr

1 year ago

Can we use an analog pin to connect the data pin of the sensor ?

0
None
GeeksTipsDotCom

1 year ago

Very thorough! Just want to mention that the DC is actually between 3.3v - 6v considering the datasheet provided by Sparkfun. If you don't know what sensor to use in your project you can see here a comparison between DHT22 and DS18B20

0
None
bonsaiclub

1 year ago

Μπόμπα! Thanks!

0
None
jurgen.geldhof.1

2 years ago

The 10k resistor seems to be missing here!

0
None
Orion96

2 years ago

Thanks for this, real help for the beginners.

One prob though, my humidity shows around 8% and i know that is deffinitely not right, it's winter here, any ideas??

thanks in advance.

0
None
Orion96

2 years ago

Thanks for this, real help for the beginners.

One prob though, my humidity shows around 8% and i know that is deffinitely not right, it's winter here, any ideas??

thanks in advance.

0
None
WynneC

2 years ago

For those having problems with the DHT library...

Download the library from https://github.com/adafruit/DHT-sensor-library (download zip).

In the Arduino development environment, use the menus: Sketch -> Import Library -> Add Library

Find the zip you downloaded and open it.

Compile your program.