#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22
#define pinbuzzer 9
#define biru 3
#define kuning 4
#define merah 5
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
pinMode(biru, OUTPUT);
pinMode(kuning, OUTPUT);
pinMode(merah, OUTPUT);
}
void loop() {
delay(100);
int t = dht.readTemperature();
if (t < 29)
{
digitalWrite(biru, HIGH);
digitalWrite(kuning, LOW);
digitalWrite(merah, LOW);
noTone(pinbuzzer);
}
else if (t > 29 && t < 35)
{
digitalWrite(kuning, HIGH);
digitalWrite(biru, LOW);
digitalWrite(merah, LOW);
noTone(pinbuzzer);
}
else if (t > 35)
{
digitalWrite(merah, HIGH);
digitalWrite(kuning, LOW);
digitalWrite(biru, LOW);
tone(pinbuzzer,500);
}
Serial.print(t);
}