The AM2302 sensor, also known as the DHT22, is a reliable digital sensor that measures both humidity and temperature. It combines a capacitive humidity sensor and a thermistor to provide accurate readings of the surrounding environment. This sensor is widely used in applications such as weather stations, home automation systems, and HVAC monitoring due to its ease of use and precision.
Pin Number | Name | Description |
---|---|---|
1 | VDD | Power supply (3.3 to 5V DC) |
2 | DATA | Digital output pin |
3 | NC | Not connected |
4 | GND | Ground |
To interface the AM2302 with an Arduino UNO, follow these steps:
#include "DHT.h"
#define DHTPIN 2 // Digital pin connected to the DHT sensor
#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);
// Reading temperature or humidity takes about 250 milliseconds!
float humidity = dht.readHumidity();
// Read temperature as Celsius (the default)
float temperature = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Celsius (isFahrenheit = false)
float heatIndex = dht.computeHeatIndex(temperature, humidity, false);
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("% Temperature: ");
Serial.print(temperature);
Serial.print("°C Heat index: ");
Serial.print(heatIndex);
Serial.println("°C");
}
Q: How often can I read data from the sensor? A: The AM2302 should not be read more frequently than every 2 seconds to ensure accurate measurements.
Q: Can the sensor be used outdoors? A: Yes, but it should be protected from direct sunlight, rain, and condensation.
Q: Is the sensor waterproof? A: No, the AM2302 is not waterproof and should be protected from water and high humidity that can condense.
For further assistance, consult the datasheet or contact the manufacturer's technical support.