Description
Tutorial: How to use AM2302 / DH22
The AM2302 / DH22 is a temperature and humidity sensor that allows for precise monitoring of environmental conditions. Ideal for home or laboratory monitoring projects.
What you need
- Arduino Uno or compatible
- USB cable
- Connect to PC
Steps
- Connect VCC to 5V of the Arduino
- Connect GND to GND of the Arduino
- Connect DATA to a digital pin of the Arduino (e.g., 2)
- Install the Adafruit_AM2315 library (or similar) from the Arduino IDE
- Check the datasheet for the specific pins of your sensor
- Write the example sketch provided by the library
- Upload the sketch to the Arduino
- View the temperature and humidity data on the serial monitor
Example code
Include <Adafruit_AM2315.h>
Adafruit_AM2315 am2315 = Adafruit_AM2315();
void setup() {
Serial.begin(9600);
if(!am2315.begin()) {
Serial.println(F("Errore durante l'inizializzazione del sensore"));
while(1);
}
}
void loop() {
float temperatura = am2315.readTemperature();
float umidita = am2315.readHumidity();
Serial.print(temperatura);
Serial.print(", ");
Serial.println(umidita);
delay(2000);
}
Mini project
Create an alarm system that sends an SMS message when the temperature exceeds a certain limit. Use a GSM module or similar.
Common mistakes
- Pin connection error
- Library not installed correctly
- Insufficient power supply issues
- Data not read correctly
Recommended accessories
- GSM module for alarm
- LCD display for data visualization
- Backup battery for Arduino
- Ethernet cable for internet connection
Frequently asked questions
The sensor is not working
Check the pin connections and power supply. Ensure the library is installed correctly.
Where can I find the datasheet?
The datasheet is available on the manufacturer’s website or on GitHub.
Can I use the sensor with Raspberry Pi?
Yes, but you might need to use a different library or a logic level converter.




Reviews
There are no reviews yet.