#include <DHT.h> // DHT 라이브러리를 포함합니다.
// DHT22 센서를 연결한 핀 번호
#define DHTPIN 4 // 변경 가능
// DHT22 센서의 타입 (DHT11, DHT21, DHT22 중 하나를 선택)
#define DHTTYPE DHT22 // DHT22를 사용하므로 DHTTYPE을 DHT22로 설정
# define LED_PIN 32
// DHT 객체 생성
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600); // 시리얼 통신 시작
pinMode(LED_PIN, OUTPUT);
dht.begin(); // DHT 센서 초기화
}
void loop() {
// 온도 및 습도 읽기
float temperature = dht.readTemperature(); // 온도 읽기
float humidity = dht.readHumidity(); // 습도 읽기
if (temperature >= 50.0 && humidity >= 80.0) {
digitalWrite(LED_PIN, HIGH);
Serial.println("Alert: Temperature and humidity are high!");
} else {
digitalWrite(LED_PIN, LOW);
}
// 읽은 온도와 습도를 시리얼 모니터에 출력
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C, Humidity: ");
Serial.print(humidity);
Serial.println(" %");
delay(1000);
}