ini adalah wiring diagramnya |
- #include <Wire.h>
- #include <DHT.h>
- #include <RTClib.h>
- #include <LiquidCrystal_I2C.h>
- #define DHTPIN A0
- #define DHTTYPE DHT11
- DHT dht(DHTPIN, DHTTYPE);
- LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x3F, 20, 4);
- RTC_DS3231 rtc;
- char namaHari[7][12] = {"Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"};
- byte sd = B11011111 ;
- void setup() {
- Serial.begin(9600);
- lcd.begin();
- rtc.begin();
- lcd.backlight();
- dht.begin();
- }
- void loop() {
- delay(1000);
- float h = dht.readHumidity();
- float t = dht.readTemperature();
- if (isnan(h) || isnan(t))
- {
- Serial.println("Tidak menemukan sensor DTH");
- lcd.print("Tidak menemukan sensor DTH");
- return;
- }
- Serial.print("Kelembapan: ");
- Serial.print(h);
- Serial.print(" %\t");
- Serial.print("Temperature: ");
- Serial.print(t);
- Serial.println(" *C ");
- DateTime now = rtc.now ();
- lcd.setCursor(0,0);
- lcd.print("Jam :");
- if(now.hour()< 10) {lcd.print ("0");
- lcd.print(now.hour());}
- else
- {lcd.print(now.hour());}
- lcd.print(":");
- if(now.minute()< 10) {lcd.print ("0");
- lcd.print(now.minute());}
- else
- {lcd.print(now.minute());}
- lcd.print(":");
- if(now.second()< 10)
- {lcd.print("0");
- lcd.print(now.second());
- }
- else
- {lcd.print(now.second());
- }
- lcd.setCursor(0,1);
- lcd.print("Tgl :");
- lcd.print(namaHari[now.dayOfTheWeek()]);
- lcd.print(",");
- lcd.print(now.day());
- lcd.print("/");
- lcd.print(now.month());
- lcd.print("/");
- lcd.print(now.year());
- lcd.setCursor(0,2);
- lcd.print("Suhu :");
- lcd.print (t);
- lcd.write(sd);
- lcd.print("C");
- lcd.setCursor(0,3);
- lcd.print("Lembab:");
- lcd.print (h);
- lcd.print("%");
- }
No comments:
Post a Comment