Thursday, April 23, 2020

Jam suhu arduino




     Link CHANNEL YOUTUBE disini     




ini adalah wiring diagramnya


     Link video disini     





  1. #include <Wire.h>
  2. #include <DHT.h>
  3. #include <RTClib.h>
  4. #include <LiquidCrystal_I2C.h>
  5. #define DHTPIN  A0   
  6. #define DHTTYPE DHT11  
  7. DHT dht(DHTPIN, DHTTYPE);
  8. LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x3F, 20, 4);
  9. RTC_DS3231 rtc;
  10. char namaHari[7][12] = {"Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"};
  11. byte sd  = B11011111 ;
  12. void setup() {
  13.  Serial.begin(9600);
  14.  lcd.begin();
  15.  rtc.begin();
  16.  lcd.backlight();
  17.  dht.begin();

  18. }

  19. void loop() {
  20.    delay(1000);
  21.   float h = dht.readHumidity();
  22.   float t = dht.readTemperature();
  23.   if (isnan(h) || isnan(t))
  24.     {
  25.      Serial.println("Tidak menemukan sensor DTH");
  26.      lcd.print("Tidak menemukan sensor DTH");
  27.      return;
  28.     }
  29.   Serial.print("Kelembapan: ");
  30.   Serial.print(h);
  31.   Serial.print(" %\t");
  32.   Serial.print("Temperature: ");
  33.   Serial.print(t);
  34.   Serial.println(" *C ");
  35.  
  36. DateTime now = rtc.now ();
  37. lcd.setCursor(0,0);
  38.   lcd.print("Jam   :");
  39. if(now.hour()< 10) {lcd.print ("0");
  40.   lcd.print(now.hour());}
  41.  else
  42.   {lcd.print(now.hour());}
  43.   lcd.print(":");
  44. if(now.minute()< 10) {lcd.print ("0");
  45.   lcd.print(now.minute());}
  46.  else
  47.   {lcd.print(now.minute());}
  48.   lcd.print(":");
  49. if(now.second()< 10)
  50.   {lcd.print("0");
  51.   lcd.print(now.second());
  52.  }
  53. else
  54.   {lcd.print(now.second());
  55.  }
  56. lcd.setCursor(0,1);
  57.   lcd.print("Tgl   :");
  58.   lcd.print(namaHari[now.dayOfTheWeek()]);
  59.   lcd.print(",");
  60.   lcd.print(now.day());
  61.   lcd.print("/");
  62.   lcd.print(now.month());
  63.   lcd.print("/");
  64.   lcd.print(now.year());

  65.  lcd.setCursor(0,2);
  66.    lcd.print("Suhu  :");
  67.    lcd.print (t);
  68.    lcd.write(sd);
  69.    lcd.print("C");
  70.  
  71.  lcd.setCursor(0,3);
  72.    lcd.print("Lembab:");
  73.    lcd.print (h);
  74.    lcd.print("%");
  75.    }

No comments:

Post a Comment