Jika pada tutorial sebelumnya kita berhasil menampilkan jadwal waktu sholat di layar serial monitor arduino IDE, tentu tidaklah sulit jika kita gunakan layar LCD 20x4 sebagai display jadwal waktu sholat harian.

Dengan ditampilkan di layar LCD, ini bisa menjadi gadget sederhana untuk saya agar saya tidak melewati kewajiban saya untuk menunaikan ibadah sholat 5 waktu di awal waktu. Saking asyiknya ngoding di kantor terkadang membuat saya lupa kalau waktu sholat sudah tiba, ditambah lagi speaker adzan dari mushola terdekat tidak terdengar dari dalam kantor 😄.

Masih menggunakan rangkaian komponen-komponen seperti pada tutorial "Menampilkan Real Time tanggal dan Jam di Layar LCD 20x4", saya akan membuat display jam digital dan jadwal waktu sholat.

Berikut rangkaiannya:

wiring diagram wemos d1 r1 i2c lcd 20x4

Dan berikut sketch programnya:

#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h> 
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>

#include <Wire.h>  // I2C library already built in Arduino IDE
#include <LiquidCrystal_I2C.h> //library via Include Library > Manage Library > 

LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); 
//0x27 is i2c address, EN,RW ,RS ,D4,D5,D6,D7 

/* Set these to your desired credentials. */
const char *ssid     = "YOUR_WIFI_NETWORK_NAME";   
const char *password = "YOUR_WIFI_PASSWORD";

//Web/Server address to read/write from 
const char *host = "api.myquran.com";
const int httpsPort = 443;  //HTTPS= 443 and HTTP = 80

//SHA1 finger print of certificate use web browser to view and copy
const char fingerprint[] PROGMEM = "95:3F:1A:FF:CB:5F:DA:AE:D0:B7:C8:C6:EF:80:81:8D:08:7D:05:24";

const long utcOffsetInSeconds = 3600;

String daysOfTheWeek[7] = {"Ahad  ", "Senin ", "Selasa", "Rabu  ", "Kamis ", "Jumat ", "Sabtu "};
String months[12]={"Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des"};

String strMMDD = "NA";
String strMMDDLast = strMMDD;
String strYY;

char jamsolat[5];
String SubuhTime, DzuhurTime, AsharTime, MaghribTime, IsyaTime;

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "id.pool.ntp.org", utcOffsetInSeconds);

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_OFF);        //Prevents reconnection issue (taking too long to connect)
  delay(1000);
  WiFi.mode(WIFI_STA);        //Only Station No AP, This line hides the viewing of ESP as wifi hotspot
  
  WiFi.begin(ssid, password);     //Connect to your WiFi router
  Serial.println("");

  Serial.print("Connecting");
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  //If connection successful show IP address in serial monitor
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());  //IP address assigned to your ESP

  timeClient.begin();
  timeClient.setTimeOffset(25200);

  lcd.begin(20,4);   // initializing the LCD 16 x 2
  lcd.setBacklightPin(3,POSITIVE); // Enable or Turn On the backlight 
  lcd.setBacklight(LOW);

  lcd.home();
  lcd.print("Assalamu'alaikum"); // Start Print text to Line 1
  lcd.setCursor(0, 1);      
  lcd.print("--------------------"); // Start Print Test to Line 2

  delay(1000);
}

void loop() {
  timeClient.update();

  strMMDD = String(timeClient.getMonth())+"/"+String(timeClient.getDate());

  if (strMMDDLast != strMMDD) {
    lcd.clear();
    
    strMMDDLast = strMMDD;
    strYY = String(timeClient.getYear());

    Serial.print("Str M/D last = ");
    Serial.println(strMMDDLast);

    getSholatTime();
  } else {
    lcd.setCursor(0, 0);
    lcd.print(daysOfTheWeek[timeClient.getDay()]);

    if (int(timeClient.getDate()) > 9) {
      lcd.setCursor(7, 0);
      lcd.print(timeClient.getDate());
    } else {
      lcd.setCursor(7, 0);
      lcd.print("0");
      lcd.setCursor(8, 0);
      lcd.print(timeClient.getDate());
    }
  
    lcd.setCursor(10, 0);
    lcd.print(months[int(timeClient.getMonth()) - 1]);
    
    if (int(timeClient.getHours()) > 9) {
      lcd.setCursor(15, 0);
      lcd.print(timeClient.getHours());
    } else {
      lcd.setCursor(15, 0);
      lcd.print("0");
      lcd.setCursor(16, 0);
      lcd.print(timeClient.getHours());
    }
    
    lcd.setCursor(17, 0);
    lcd.print(":");
  
    if (int(timeClient.getMinutes()) > 9) {
      lcd.setCursor(18, 0);
      lcd.print(timeClient.getMinutes());
    } else {
      lcd.setCursor(18, 0);
      lcd.print("0");
      lcd.setCursor(19, 0);
      lcd.print(timeClient.getMinutes());
    }

    delay(1000);
  }
}

void getSholatTime() {
  WiFiClientSecure httpsClient;    //Declare object of class WiFiClient

  Serial.println(host);
  Serial.printf("Using fingerprint '%s'\n", fingerprint);
  httpsClient.setFingerprint(fingerprint);
  httpsClient.setTimeout(15000); // 15 Seconds
  delay(1000);
  
  Serial.print("HTTPS Connecting");
  int r=0; //retry counter
  while((!httpsClient.connect(host, httpsPort)) && (r < 30)){
      delay(100);
      Serial.print(".");
      r++;
  }
  if(r==30) {
    Serial.println(". Connection failed");
  }
  else {
    Serial.println(". Connected to web");
  }
  
  String Link;
  //GET Data
  Link = "/v1/sholat/jadwal/1204/20"+strYY+"/"+strMMDD; //address from which we need to get the data inside the server.

  Serial.print("requesting URL: ");
  Serial.println(host+Link);

  httpsClient.print(String("GET ") + Link + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +             
               "Connection: close\r\n\r\n");

  Serial.println("request sent");
                  
  while (httpsClient.connected()) {
    String line = httpsClient.readStringUntil('\n');
    if (line == "\r") {
      Serial.println("headers received");
      break;
    }
  }

  Serial.println("reply was:");
  Serial.println("==========");
  String line;
  while(httpsClient.available()){        
    line = httpsClient.readStringUntil('\n');  //Read Line by Line

    // Get Subuh time ///////////////////
    int pos1 = line.indexOf("\"subuh\"");
    if (pos1 >= 0) {
      int j = 0;
      for(j=0; j<5; j++){
        jamsolat[j] = line[pos1 + 9 + j];
      }
      SubuhTime = jamsolat;
    }
    //////////////////////////////////////

    // Get Dzuhur time ///////////////////
    int pos2 = line.indexOf("\"dzuhur\"");
    if (pos2 >= 0) {
      int k = 0;
      for(k=0; k<6; k++){
        jamsolat[k] = line[pos2 + 10 + k];
      }
      DzuhurTime = jamsolat;
    }
    //////////////////////////////////////

    // Get Ashar time ////////////////////
    int pos3 = line.indexOf("\"ashar\"");
    if (pos3 >= 0) {
      int l = 0;
      for(l=0; l<5; l++){
        jamsolat[l] = line[pos3 + 9 + l];
      }
      AsharTime = jamsolat;
    }
    //////////////////////////////////////

    // Get Maghrib time //////////////////
    int pos4 = line.indexOf("\"maghrib\"");
    if (pos4 >= 0) {
      int m = 0;
      for(m=0; m<7; m++){
        jamsolat[m] = line[pos4 + 11 + m];
      }
      MaghribTime = jamsolat;
    }
    //////////////////////////////////////

    // Get Isya time ////////////////////
    int pos5 = line.indexOf("\"isya\"");
    if (pos5 >= 0) {
      int n = 0;
      for(n=0; n<5; n++){
        jamsolat[n] = line[pos5 + 8 + n];
      }
      IsyaTime = jamsolat;
    }
    //////////////////////////////////////

    SubuhTime = SubuhTime.substring(0,5);
    DzuhurTime = DzuhurTime.substring(0,5);
    AsharTime = AsharTime.substring(0,5);
    MaghribTime = MaghribTime.substring(0,5);
    IsyaTime = IsyaTime.substring(0,5);

    Serial.println("Subuh   : "+SubuhTime);
    Serial.println("Dzuhur  : "+DzuhurTime);
    Serial.println("Ashar   : "+AsharTime);
    Serial.println("Maghrib : "+MaghribTime);
    Serial.println("Isya    : "+IsyaTime);
    Serial.println("----- ### -----");
  }
  Serial.println("==========");
  Serial.println("closing connection");

  lcd.setCursor(0, 1);
  lcd.print("Dzuhur : ");
  lcd.setCursor(9, 1);
  lcd.print(DzuhurTime);

  lcd.setCursor(0, 2);
  lcd.print("Ashar  : ");
  lcd.setCursor(9, 2);
  lcd.print(AsharTime);

  lcd.setCursor(0, 3);
  lcd.print("Maghrib: ");
  lcd.setCursor(9, 3);
  lcd.print(MaghribTime);

  delay(1000);
}

            

Copy paste sketch program di atas ke Arduino IDE kemudian upload. Jika upload berhasil maka layar LCD 20x4 akan menampilkan jadwal waktu sholat dilengkapi dengan tanggal dan jam seperti di bawah ini:

jadwal waktu sholat lcd 20x4

Jadwal waktu sholat yang saya tampilkan di layar LCD yaitu waktu Dzuhur, Ashar dan Maghrib karena waktu-waktu tersebut yang akan saya laksanakan sholat selama bekerja di kantor. Bukan berarti saya engga sholat Subuh dan Isya ya ... 😄