Muslim Prayer Time Alarm Countdown Clock - Lane Tech
by meawan in Circuits > Microcontrollers
159 Views, 0 Favorites, 0 Comments
Muslim Prayer Time Alarm Countdown Clock - Lane Tech
As a Muslim we have to pray 5 times a day at varying times, which are dependent on the position of the sun. So as you can imagine every day these prayer times are always changing. Therefore it can be difficult to keep track of which prayer time it is or how much time you have remaining until the next one. Thats where this project comes in. It retrieves prayer times from an online api and sets an automated alarm system that sets off a countdown timer whenever it is time to read that prayer.
Supplies
- Argon
- Wires ( a lot of them)
- Buzzer
- 7 Segment Display
Retrieving Prayer Times
The first step was actually retrieving the prayer times from an external source.
I used aladhan.com/prayer-times-api which is an online database that stores Muslim prayer times for public use.
To retrieve the times in my code I used a webhook with a get request. The data from the url was already in JSON format so all I had to do was read the JSON Doc and extract the specific times I needed.
Automated Alarm
Next I wrote an if statement inside the loop() which constantly checked if any of the times that were retrieved in Step 1 matched with the current time.
I got the current time by using the Time class:
Time.now();
However I needed it to be in the format "HH:MM" so I could compare it with the prayer times (because they were also in this format) to see if any of them matched.
I did this by using .format()
Time.format(Time.now(), "%H:%M");
After having both the prayer time, and the current time, all that was left was a simple if statement which checked if both were the same and if they were it would call the buzzer which played a sound (acting as an alarm).
Calculating Countdown Time
After the buzzer finishes ringing, we need to calculate the amount of time until the next prayer so we can start a countdown timer on the 7 segment display.
The way I did this step was by getting substrings of both the hour and the minute for both times
- Both times being 1, the current time and 2, the time for the next prayer
String hours1 = CurrentTime.substring(0, 2);
String minutes1 = CurrentTime.substring(3);
String hours2 = nextPrayer.substring(0, 2);
String minutes2 = nextPrayer.substring(3);
Then Convert both substrings into an int and subtract them.
int hourDiff = hours2.toInt() - hours1.toInt();
int minuteDiff = minutes2.toInt() - minutes1.toInt();
Finally store this new time in an int and return that.
int totalMinutes = hourDiff + minuteDiff;
return totalMinutes;
Start Countdown on Display
Displaying the time from the last step on the 7 segment display and starting the countdown.
I did this by creating a while loop that runs until the countdown time is = to 0.
Every time the loop runs it adds to a counter variable. When this counter is = to 60 it subtracts one from the time. The purpose of this is to imitate passing of a minute on the display.
If at any point the minute side reaches 0 we subtract 40 from the total time to imitate change of an hour to 60 minutes.
When the timer reaches 0 the buzzer plays a sound and ideally it will now have been time for the next prayer and the whole process will repeat again for the next prayer.