Skip to content Skip to sidebar Skip to footer

Widget HTML #1

Prayer Times Using Arduino C++

Prayer Times Using Arduino C++

Prayer Times Using Arduino C++ -  In this post I provide a basic program to be able to display prayer times automatically just by entering the coordinates, time zone, date, month and year.
arduino pray time program
Image from Pixabay


I got a really nice library on Github called Arduino-Prayer-Times posted by asmaklad (don't know if this is someone's name). This library is the result of conversion from http://praytimes.org/manual/. Thank you prayertimes.org and asmaklad!

After I tried this library, I compared it with the (KEMENAG-INDONESIA) prayer times and there were differences. From that, I slightly modified the Prayer Times library. You can download the edited Library link by clicking the following download button:


Sample code is as follows:

#include "PrayerTimes.h"


double waktu[sizeof(TimeName) / sizeof(char*)];

//------- Silahkan ubah data di sini ------------------
/* Koordinat dapat di ambil di Google Map
  Contoh koordinat program ini adalah :
  Mesjid Istiqomah
  Hulu, Tapak Tuan, Kabupaten Aceh Selatan, Aceh 23715
  3.258053, 97.179334
*/

float _lat = 3.257778;    // lintang
float _lng = 97.179289;   // bujur

int _tahun = 2020;
int _bulan = 1;
int _tanggal = 13;

int _timezone = 7;        //  WIB=7, WITA=8, WIT=9

int koreksi_imsak    = -8;
int koreksi_subuh    = 2;
int koreksi_terbit   = -3;
int koreksi_dhuha    = 24;
int koreksi_zuhur    = 3;
int koreksi_ashar    = 3;
int koreksi_terbenam = 1;
int koreksi_magrib   = 3;
int koreksi_isya     = 3;
//---------------------------------------------------

// sudut subuh dan maghrib Indonesia
int _sudut_subuh = 20;
int _sudut_isyak = 18;

int hours, minutes;

void setup() {

  Serial.begin(9600);

  set_calc_method(ISNA);  // metode perhitungan
  set_asr_method(Shafii); // madzhab?
  set_high_lats_adjust_method(AngleBased);
  set_fajr_angle(_sudut_subuh);     // sudut waktu subuh
  set_isha_angle(_sudut_isyak);     // sudut waktu isyak

}

void loop() {
  get_prayer_times(_tahun, _bulan, _tanggal, _lat, _lng, _timezone, waktu);

  for (int i = 0; i < 9; i++) {

    get_float_time_parts(waktu[i], hours, minutes);

    if (i == 0) { //Imsak
      minutes = minutes + koreksi_imsak;
      cek_menit();
    }

    if (i == 1) { //Subuh
      minutes = minutes + koreksi_subuh ;
      cek_menit();
    }

    if (i == 2) { //Terbit
      minutes = minutes + koreksi_terbit;
      cek_menit();
    }

    if (i == 3) { //Dhuha
      minutes = minutes + koreksi_dhuha;
      cek_menit();
    }

    if (i == 4) { //Zhuhur
      minutes = minutes + koreksi_zuhur;
      cek_menit();
    }

    if (i == 5) { //Ashar
      minutes = minutes + koreksi_ashar;
      cek_menit();
    }

    if (i == 6) { //Terbenam
      minutes = minutes + koreksi_terbenam;
      cek_menit();
    }

    if (i == 7) { //Magrib
      minutes = minutes + koreksi_magrib;
      cek_menit();
    }

    if (i == 8) { //Isya
      minutes = minutes + koreksi_isya ;
      cek_menit();
    }

    Serial.print(i);
    Serial.print(". ");
    Serial.print(TimeName[i]);
    Serial.print("  ");
    Serial.print(hours);
    Serial.print(":");
    Serial.println(minutes);
  }
  delay(6000);
  Serial.println();

}
void cek_menit() {
  if (minutes == 60) {
    minutes = 0;
    hours = hours + 1;
  }
  if (minutes <= -1) {
    minutes = 60 - (-minutes);
    hours = hours - 1;
  }
  if (minutes >= 61) {
    minutes = minutes - 60;
    hours = hours + 1;
  }
}

After the code is uploaded to Arduino, using a serial monitor shows the following results:Prayer Times Using Arduino C++

If friends have suggestions and criticisms, please comment below. May be useful.

Post a Comment for "Prayer Times Using Arduino C++"