Skip to main content

How to use-DTH22 Sensor


Humidity and Temperature


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.

Picture






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
Picture

What you will need - Hardware

For this tutorial you will need:
  • Arduino uno
  • Breadboard
  • DHT-22
Picture

The Circuit

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

The code ::

Picture

Here's the code,
*************************************************************************************
/* How to use the DHT-22 sensor with Arduino uno
   Temperature and humidity sensor
 */

//Libraries
#include "dht.h";

//Constants
dht DHT;
const int dhtPin = 2; //Data pin of DHT-22 to Arduino digital pin 2

//Variables
int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value

void setup()
{
    Serial.begin(9600);
}

void loop()
{
chk = DHT.read22(dhtPin); //Check data pin and read values
    //Read data and store it to variables hum and temp
    hum = DHT.humidity;
    temp= DHT.temperature;
    //Print temp and humidity values to serial monitor
    Serial.print("Humidity: ");
    Serial.print(hum);
    Serial.print(" %, Temp: ");
    Serial.print(temp);
    Serial.println(" Celsius");
    delay(2000); //Delay 2 sec.
}
  
*************************************************************************************

Well done!

Picture
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.

Comments

Popular posts from this blog

Arduino ​Obstacle Avoiding Robot Ardunio Computer

Build Your Own Arduino Weather Station

Complete Guide for Nokia 5110 LCD with Arduino