Introduction: How to Use DHT-22 Sensor - Arduino Tutorial

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!

Comments

author
ChandruS6 (author)2017-07-28

But Great Project I already made it!

author
ChandruS6 (author)2017-07-28

Where I should get the DHT22.h Library?

❓❓❓❓❓❓❓

author
banjabi1 (author)2017-07-23

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

author
banjabi1 (author)banjabi12017-07-23

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

author
soardr (author)2017-03-11

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

author
charliescarface (author)2017-01-12

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

author
GeeksTipsDotCom (author)2016-12-11

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

author
bonsaiclub (author)2016-11-17

Μπόμπα! Thanks!

author
jurgen.geldhof.1 (author)2016-11-11

The 10k resistor seems to be missing here!

author
sridharj2 (author)2016-11-07

NICE

author
Nygreekkid93 (author)2016-09-22

Μπόμπα!

author
Orion96 (author)2016-05-09

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.

author
Orion96 (author)2016-05-09

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.

author
WynneC (author)2016-03-22

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.

author
JayM83 (author)2016-03-02

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.

author
chrish56 (author)2016-02-15

Thanks! This helped!

author
Shankar AnanthA made it! (author)2016-01-23

Very nice and easy tutorial!

P1080445.JPG
author
Shankar AnanthA made it! (author)2016-01-23

Very nice and easy tutorial!

P1080445.JPG
author
hornerj99 (author)2015-12-03

Don't you need a 10k resistor in there?

author
specialk802 (author)2015-11-27

Downloaded the Codebender and followed all of the steps however when I click on "Run on Arduino" all I get is error in compiling...not sure what to do. Tried uploading through the IDE but that failed do to the following errors.

sketch_nov27a:10: error: 'dht' does not name a type

sketch_nov27a.ino: In function 'void loop()':

sketch_nov27a:25: error: 'DHT' was not declared in this scope

If you could help me resolve either it would be much appreciated.

author
John-ArvidK (author)2015-07-08

Good and easy instructable. I just have a question about the dht library, what did you use? I found one but it gives me errors on the variables.

author

Hi! Thank you for your comment. Just connect the Arduino with pc and click on "Run on Arduino" button to program your Arduino board with this sketch.

No need to run Arduino IDE or install additional library ;)

Try it!

author
Saiyam (author)2015-07-01

Your series of arduino tutorials are really helpful!

author
codebender_cc (author)Saiyam2015-07-02

I'm glad that they're helpful. Thank you

About This Instructable

138,281views

64favorites

License:

Bio: Arduino Tutorials by Codebender.cc Team
More by codebender_cc:How to use a magnetic door switch / sensor with ArduinoHow to Measure LUX With ArduinoHow to Control an RGB LED Strip - Arduino Tutorial
Add instructable to: