Home Sensor Projects DHT22 sensor example

DHT22 sensor example

by shedboy71

In this example we use the DHT22 (or AM2302) humidity/temperature sensor and the Arduino UNO board to read data and print it out to the serial monitor.

The DHT22 is better than the DHT11 because it has a wider range of measurement, 0 to 100% for humidity and -40°C to +125°C for temperature. Also it has a digital output that provides greater data accuracy.

AM2302 capacitive humidity sensing digital temperature and humidity module is one that contains the compound has been calibrated digital signal output of the temperature and humidity sensors. Application of a dedicated digital modules collection technology and the temperature and humidity sensing technology, to ensure that the product has high reliability and excellent long-term stability. The sensor includes a capacitive sensor wet components and a high-precision temperature measurement devices, and connected with a high-performance 8-bit microcontroller.

The product has excellent quality, fast response, strong anti-jamming capability, and high cost. Each sensor is extremely accurate humidity calibration chamber calibration. The form of procedures, the calibration coefficients stored in the microcontroller, the sensor within the processing of the heartbeat to call these calibration coefficients.

I used a breakout but here is how to wire the device to your Arduino Uno

uno and dht22

uno and dht22

Code

[codesyntax lang=”cpp”]

#include "DHT.h"
 
#define DHTPIN 6     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)

 
DHT dht(DHTPIN, DHTTYPE);
 
void setup() 
{
  Serial.begin(9600); 
  dht.begin();
}
 
void loop() 
{
  // Wait a few seconds between measurements.
  delay(2000);
 
  float hum = dht.readHumidity();
  // Read temperature as Celsius
  float tempC = dht.readTemperature();
  
  // Check if readings have failed
  if (isnan(hum) || isnan(tempC)) 
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }     
  
  Serial.print("Humidity: "); 
  Serial.print(hum);
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.print(tempC);
  Serial.println(" *C ");
 
}

[/codesyntax]

 

Links
DHT22 Digital Humidity AM2302 and Temperature Sensor Module

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More