#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd (0x27, 20, 4);
DHT dht = DHT(DHTPIN, DHTTYPE);
char namaHari[7][12] = {"Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"};
void setup () {
Serial.begin(9600);
lcd.init();
lcd.backlight();
dht.begin();
if (! rtc.begin()) {
Serial.println("RTC TIDAK TERBACA");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop () {
float suhu = dht.readTemperature();
float hic = dht.computeHeatIndex(suhu, false);
Serial.print("Temperature: ");
Serial.print(suhu);
Serial.print(" \xC2\xB0");
Serial.print("C | ");
Serial.println(" ");
lcd.setCursor(2, 0);
lcd.noAutoscroll();
lcd.print(suhu);
if (suhu < 20 ) {
lcd.print("=Suhu Dingin");
}
else if (suhu >= 20 && suhu <= 50 ) {
lcd.print("=Suhu Biasa");
}
else if (suhu > 50){
lcd.print("=Suhu Panas!!!");
}
lcd.setCursor(0, 1);
lcd.scrollDisplayLeft();
DateTime now = rtc.now();
lcd.print(namaHari[now.dayOfTheWeek()]);
lcd.print(',');
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.year(), DEC);
lcd.print(" ");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.println();
delay(400);
}