#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define DHTPIN 2
#define LEDPIN 5
#define BUZZERPIN 8
#define LDRPIN A0
#define DHTTYPE DHT22
DHT dht (DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
dht.begin();
pinMode(BUZZERPIN, OUTPUT);
pinMode(LEDPIN, OUTPUT);
lcd.setCursor(0,0);
lcd.print("Praktikum Embedded System");
lcd.setCursor(0,1);
lcd.print("Lab Teknik Digital");
int positionCounter;
for (positionCounter = 0; positionCounter < 24; positionCounter++) {
lcd.scrollDisplayLeft();
delay(300);
}
lcd.clear();
}
void loop() {
// put your main code here, to run repeatedly:
if (millis() > 10000) {
int ldrValue = analogRead(LDRPIN);
float temp = dht.readTemperature();
float hum = dht.readHumidity();
lcd.setCursor(0,0);
lcd.print("T:");
lcd.print(temp);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("H:");
lcd.print(hum);
lcd.print("%");
if (temp > 40) {
tone(BUZZERPIN, 2000);
} else {
noTone(BUZZERPIN);
}
analogWrite(LEDPIN, ldrValue - 8);
}
delay(1000);
}