Friday 8 September 2017

DHT22 Temperature and humidity sensor interface with arduino


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). Its fairly simple to use, but requires careful timing to grab data. The only real downside of this sensor is you can only get new data from it once every 2 seconds, so when using our library, sensor readings can be up to 2 seconds old.


Simply connect 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. Although it uses a single-wire to send data

TECHNICAL DETAILS



  • Low cost
  • 3 to 5V power and I/O
  • 2.5mA max current use during conversion (while requesting data)
  • Good for 0-100% humidity readings with 2-5% accuracy
  • Good for -40 to 80°C temperature readings ±0.5°C accuracy
  • No more than 0.5 Hz sampling rate (once every 2 seconds)
  • Body size 27mm x 59mm x 13.5mm (1.05" x 2.32" x 0.53")
  • 4 pins, 0.1" spacing
  • Weight (just the DHT22): 2.4g

Arduino DhT22 Wiring diagram 

PROGRAMME
//                   http://electronicshobbycorner.blogspot.in
//                   Rajeev TR
//                   rajeev.emb402@gmail.com
// PROGRAM TO INTERFACE DHT22 WITH ARDUINO


#include "DHT.h"
#define DHTPIN 2                                      // what pin we're connected to
#define DHTTYPE DHT22                                 // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);
float t;

float temprature();

void setup() 
{
  Serial.begin(9600); 
  Serial.println("DHTxx test!");
  dht.begin();
}

void loop() 
{
  float k=  temprature();
  if(Serial.available())
  {
            char x;
            x=Serial.read();
            if(x=='a')
            {
                Serial.print("Temperature: "); 
                Serial.print(t);
                Serial.print(" *C ");
                Serial.println(); 
             }
  }

}
float temprature()
{
      float h = dht.readHumidity();
      t = dht.readTemperature();
      float f = dht.readTemperature(true);
      if (isnan(h) || isnan(t) || isnan(f)) 
      {
              Serial.println("Failed to read from DHT sensor!");
              return 0;
      }
      float hi = dht.computeHeatIndex(f, h);
      return t;
}

Download DHT22 Library from here
Download code from here

No comments:

Post a Comment