#include <DHT.h>
#include <Servo.h> // Library Servo
#define DHT_PIN 8
#define DHT_TYPE DHT22
#define SERVOPIN 3
Servo myservo;
DHT dht(7, DHT22);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
dht.begin();
myservo.attach(3); //Pin yang terhubung dengan arduino uno
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
delay(300);
float Suhu = dht.readHumidity();
float Kelembaban = dht.readTemperature();
myservo.write(90);
delay(1000);
myservo.write(0);
delay(1000);
if(isnan(Suhu) || isnan(Kelembaban)){
Serial.println(F("Failed to read sensor DHT"));
return;
}else{
Serial.print("Suhu:");
Serial.print(Suhu);
Serial.print("% ");
Serial.print("Kelembaban:");
Serial.print(Kelembaban);
Serial.print("°C ");
}
}