#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <DHT.h>
int buzzPin = 8;
int servoPin = 9;
int DHTPin = 2;
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo myservo;
#define DHTTYPE DHT22
DHT dht(DHTPin, DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.begin(16,2);
lcd.init();
lcd.setBacklight(HIGH);
dht.begin();
pinMode(buzzPin, OUTPUT);
myservo.attach(servoPin);
}
void loop() {
// put your main code here, to run repeatedly:
float h = dht.readHumidity();
float t = dht.readTemperature();
lcd.setCursor(0,0);
lcd.print("Suhu: ");
lcd.print(t);
lcd.setCursor(0,1);
lcd.print("Kelembapan: ");
lcd.print(h);
if(t>29){
tone(buzzPin,HIGH);
myservo.write(0);
delay(1000);
}
else{
noTone(buzzPin);
myservo.write(180);
delay(1000);
}
}