Hardware components | ||||||
| × | 1 | ||||
| × | 1 |
Full Instructions are available
at
diyusthad.com
In this project, we are going to build an ESP32-based Islamic Prayer time display. Instead of calculating the prayer time using coordinates, we are going to fetch the prayer time data from the internet using the API provided by https://aladhan.com/ and display it on an LCD display.
The API will give the response in JSON format so we use the ArduinoJSON library to process the data and display the prayer time in the LCD display.
Working Video
//program by https://diyusthad.com
#include <SPI.h>
#include <Wire.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <LiquidCrystal_I2C.h>
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
int lcdColumns = 16;
int lcdRows = 4;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
const char* data_timings_Fajr ;
const char* data_timings_Sunrise ;
const char* data_timings_Dhuhr ;
const char* data_timings_Asr ;
const char* data_timings_Sunset ;
const char* data_timings_Maghrib ;
const char* data_timings_Isha ;
const char* data_timings_Imsak ;
const char* data_timings_Midnight ;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
lcd.init();
// turn on LCD backlight
lcd.setBacklight(10);
fetchData();
}
void loop() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Fajr : ");
lcd.print(data_timings_Fajr);
lcd.setCursor(0, 1);
lcd.print("Dhuhr : ");
lcd.print(data_timings_Dhuhr);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Asr : ");
lcd.print(data_timings_Asr);
lcd.setCursor(0, 1);
lcd.print("Maghrib : ");
lcd.print(data_timings_Maghrib);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Isha : ");
lcd.print(data_timings_Isha);
delay(2000);
}
void fetchData()
{
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
Serial.print("[HTTP] begin...\n");
if (http.begin("http://api.aladhan.com/v1/timingsByCity?city=Dubai&country=United%20Arab%20Emirates&method=4")) { // API Request
Serial.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
DynamicJsonDocument doc(2048);
deserializeJson(doc, payload);
JsonObject data = doc["data"];
JsonObject data_timings = data["timings"];
data_timings = data["timings"];
data_timings_Fajr = data_timings["Fajr"]; // "05:13"
data_timings_Sunrise = data_timings["Sunrise"]; // "06:31"
data_timings_Dhuhr = data_timings["Dhuhr"]; // "12:29"
data_timings_Asr = data_timings["Asr"]; // "15:52"
data_timings_Sunset = data_timings["Sunset"]; // "18:26"
data_timings_Maghrib = data_timings["Maghrib"]; // "18:26"
data_timings_Isha = data_timings["Isha"]; // "19:56"
data_timings_Imsak = data_timings["Imsak"]; // "05:03"
data_timings_Midnight = data_timings["Midnight"]; // "00:29"
//Serial.println("fajr time:");
//Serial.println(data_timings_Fajr);
//Serial.println(data_timings_Dhuhr);
//Serial.println(data_timings_Asr);
//Serial.println(data_timings_Maghrib);
//Serial.println(data_timings_Isha);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
} else {
Serial.printf("[HTTP} Unable to connect\n");
}
}
}
Comments