Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 months ago
728 B
0
Indexable
Never
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
#define LED 12
#define buzzer 7

DHT dht(DHTPIN, DHTTYPE);
int chk;
int hum;
int temp;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  dht.begin();
  pinMode(LED, OUTPUT);
  pinMode(buzzer, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  hum=dht.readHumidity();
  temp=dht.readTemperature();
  Serial.print("Humidity: ");
  Serial.println(hum);
  Serial.print("Temperature: ");
  Serial.println(temp);

  if(temp>50||temp<-20 || hum>50 || hum<30)
  {
    digitalWrite(buzzer,HIGH);
    digitalWrite(LED,HIGH);
    delay(1000);
    digitalWrite(LED,LOW);
    digitalWrite(buzzer,LOW);
    delay(1000);
  }
}