Arduino
[Arduino Nano/나노] AM2302(DHT22) 온습도 센서
놀자요를레히
2021. 1. 28. 16:07
[Arduino Nano/나노] AM2302(DHT22) 온습도 센서
Overview
This is a calibrated digital temperature and humidity module with onboard sensor DHT22, which features higher accuracy and wider measuring range than DHT11.
It can be used for detecting ambient temperature and humidity, through the standard single-wire interface.
Specifications
- Temperature
- Resolution : 0.1°C
- Accuracy : ±0.5℃
- Measuring range : -40°C ~ 80°C
- Humidity
- Resolution : 0.1%RH
- Accuracy : ±2%RH (25°C)
- Measuring range : 0%RH ~ 99.9%RH
- Operating voltage : 3.3V ~ 5.5 V
- Recommended storage condition
- Temperature : 10°C ~40°C
- Humidity : 60%RH or below
자세한 내용은 하단의 데이터시트 참고
AM2302(DHT22) datasheet.pdf
0.58MB
아두이노 연결
AM2302(DHT22) | Arduino Nano |
GND | GND |
NC | X |
DAT | D3 |
VCC | 5V |
사용 라이브러리
아두이노 코드
// https://devicemart.blogspot.com/2019/06/dht11-dht22.html 참고
#include "DHT.h"
#define DHTPIN 3 // DAT 핀 설정
#define DHTTYPE DHT22 // DHT22 센서종류 설정
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
Serial.begin(9600);
dht.begin();
Serial.println("test start!"); Serial.println();
}
void loop()
{
// 센서의 온도와 습도를 읽어오기
float h = dht.readHumidity();
float t = dht.readTemperature();
if(isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity : "); Serial.print(h); Serial.print("%\t");
Serial.print("Temperature : "); Serial.print(t); Serial.print("℃\t");
}
}