Arduino and AM2302 humidity and temperature sensor

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

I used a breakout , again it makes the job easier and doesn’t really add to the cost of a project

DHT22 Digital Humidity AM2302 and Temperature Sensor Module For Arduino

Breadboard layout

The resistor should be 4.7k in the layout below

dht22 breadboard layout

Code

Import the DHT11 library from Adafruit, in later versions of the Arduino IDE you can do this in the library manager. You can see this in the screenshot below

dht11 library manager

[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

http://akizukidenshi.com/download/ds/aosong/AM2302.pdf

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :