#include <DHT.h>
#include <Servo.h>
#define DHTPIN 2
#define DHTTYPE DHT22
#define SERVOPIN 9
DHT dht(DHTPIN, DHTTYPE);
Servo servo;
float suhu;
float kelembapan;
float suhu_teratur;
void setup() {
servo.attach(SERVOPIN);
dht.begin();
Serial.begin(9600);
}
void loop() {
suhu = dht.readTemperature();
kelembapan = dht.readHumidity();
Serial.print("Suhu: ");
Serial.print(suhu);
Serial.print("°C ");
Serial.print("Kelembapan: ");
Serial.print(kelembapan);
Serial.print("%\n");
if (suhu < suhu_teratur) {
servo.write(0);
} else if (suhu > suhu_teratur) {
servo.write(180);
} else {
servo.write(90);
}
// Tunggu 1 detik sebelum membaca data lagi
delay(1000);
}