Prayer Time Azan Alarm Device Using Arduino

This project is a fully automated Prayer Time Azan alarm system designed for Muslim users to be reminded of the five daily prayers. It uses an Arduino Mega as the brain, a 2.4” TFT Touch Screen for user interface, a DS3231 RTC module for real-time clock and date accuracy, and a DFPlayer Mini MP3 module with speaker to play the Azan audio at the correct prayer times. The device is ideal for personal use, home installation, or small prayer areas such as offices or shops.

Prayer Time Alarm Device with Arduino

Features of Prayer Time Azan Alarm Device:

  • Automatic Azan playback at all 5 prayer times.
  • Accurate timekeeping using the DS3231 RTC.
  • 2.4-inch TFT touchscreen interface for settings and display.
  • Display of time, date, day, and prayer names.
  • Optional manual Azan trigger or test mode.
  • Adjustable volume via DFPlayer Mini’s onboard support.
  • Power via USB, adapter, or battery (optional for portability).

Components used in Prayer Time Azan Alarm Device:

Arduino Mega 2560

  • Chosen for its ample I/O pins and memory to handle TFT, audio, and RTC simultaneously.

2.4” TFT Touchscreen Display (ILI9341)

  • Used to display real-time clock, prayer times, and control interface.

DS3231 RTC Module

  • Real-Time Clock for accurate timekeeping with battery backup.

DFPlayer Mini MP3 Player Module

  • Plays pre-recorded Azan audio files stored on a microSD card.

MicroSD Card (FAT32 formatted)

  • Stores the Azan MP3 files.

4Ω 3W Speaker

  • Connected to DFPlayer Mini to play audio.

Optional: Buttons or Buzzer (for notifications or manual control)

Breadboard & Jumper Wires / Custom PCB

  • For wiring and prototyping.

Power Supply (USB Adapter / 9V Battery / 5V Adapter)

Working Principle of Prayer Time Azan Alarm Device:

Time Management:

  • The DS3231 RTC continuously keeps track of the current time and date.
  • The Arduino reads this time regularly.

Prayer Time Matching:

  • The Arduino stores predefined prayer times (or optionally adjusts using an algorithm based on latitude/longitude).
  • When the current time matches any prayer time, the DFPlayer Mini triggers the corresponding Azan audio.

Audio Playback:

  • DFPlayer Mini reads the MP3 files from the SD card.
  • MP3 files should be named and ordered properly (e.g., 001.mp3, 002.mp3…).
  • The speaker plays the Azan.

TFT Display UI:

  • Shows the current time and date.
  • Shows prayer times for Fajr, Dhuhr, Asr, Maghrib, Isha.
  • Touchscreen can be used to:
    • Adjust time
    • Manually play Azan
    • Mute sound
    • Show next prayer countdown

Circuit Diagram of Prayer Time Azan Alarm Device with Arduino:

Circuit Diagram of Prayer Time Azan Alarm Device with Arduino

Code for Prayer Time Azan Alarm Device:

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#include "Wire.h" 
#include <Fonts/FreeSans12pt7b.h> 
#include <FreeDefaultFonts.h>
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(19, 18); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

#define MINPRESSURE 200
#define MAXPRESSURE 1000


const int XP=8,XM=A2,YP=A3,YM=9; //240x320 ID=0x7789
const int TS_LEFT=129,TS_RT=887,TS_TOP=84,TS_BOT=896;

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Adafruit_GFX_Button Azaan_btn;

int pixel_x, pixel_y;     //Touch_getXY()  

//---------------------------------------------------------------------------
 
 
int xegg, yegg;
#define DS1307_I2C_ADDRESS 0x68  // This is the I2C address
long previousMillis = 0;        // will store last time time was updated
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
int hours, minutes;
int hrs, mts;
long interval = 1000;
int displayx, displayy, displayradius, x2, y2, x3, y3;
int zero = 0;
char  *Day[] = {"", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
double fajr, sunRise, zuhr, asr, maghrib, isha;
int x=0;
String Prayer, Last_msg1, Last_msg2;
bool start=true,alarm=true,PS=true,latch=true, text=true;
int Hrs[6],Mts[6];

//-----------------------------------
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
//-----------------------------------




void setup()  {
  Serial.begin(9600);
  Wire.begin();
  getDateDs1307() ;
  Initialize_Display();
  calcPrayerTimes(year, month, dayOfMonth, 39.8, 21.4, 3, -18.5, -19, fajr, sunRise, zuhr, asr, maghrib, isha); // year , month, day, Longitude, Latitude, Time Zone, Fajr Twilight, Esha Twilight
  Get_Times(); 
  printTime();

//You can uncomment these 2 lines, to test the code by typing a few minutes ahead than actual time
// as I have shown you in the video 
//  hrs=23;
//  mts=24;


   mySoftwareSerial.begin(9600);
    if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
  }
  else
  Serial.println(F("DFPlayer Mini online."));
 
}




//---------------------------------Loop Start--------------------------
void loop() {
  getDateDs1307() ;
  calcPrayerTimes(year, month, dayOfMonth, 39.8, 21.4, 3, -18.5, -19, fajr, sunRise, zuhr, asr, maghrib, isha); // year , month, day, Longitude, Latitude, Time Zone, Fajr Twilight, Esha Twilight
  Read_Button();
 
  if (hrs==hour&&mts==minute&&latch==true) 
  {  start=false; latch=false;  }
  else if (hrs==hour&&mts!=minute&&latch==false) 
  {latch=true; x++; text=true;}
  
  if (start==true)
  { Calendar(); } 
  else
  {Alarm();} 

 if (Azaan_btn.justReleased())
     {Azaan_btn.drawButton();
       start=true;
       x++;
       Update_Time();
       text=true;
       myDFPlayer.pause();
     }

  
//printTime();
}
//---------------------------------Loop End--------------------------


void Update_Time()
{
  hrs=Hrs[x];
  mts=Mts[x]; 
  }



void Calendar()
 {   
      
      
     if (text==true)
     {text=false; tft.fillScreen(BLACK); 
     showmsgXY(60, 60, 1, &FreeSans12pt7b, "Next Prayer Time", WHITE);}  
     Print_Time(70,160,(String)hrs,(String)mts,GREEN);
     alarm=true;     
  }

  void Get_Times()
  {
    doubleToHrMin(fajr, hours, minutes);
    Hrs[1]=hours;
    Mts[1]=minutes;
    doubleToHrMin(zuhr, hours, minutes); 
    Hrs[2]=hours;
    Mts[2]=minutes;
    doubleToHrMin(asr, hours, minutes);
    Hrs[3]=hours;
    Mts[3]=minutes;
    doubleToHrMin(maghrib, hours, minutes);
    Hrs[4]=hours;
    Mts[4]=minutes;
    doubleToHrMin(isha, hours, minutes);  
    Hrs[5]=hours;
    Mts[5]=minutes;
    
    
    }



void printTime()
{
  
  char s[12];

  Serial.print(Day[dayOfWeek]);
  Serial.print(":");
  Serial.print(char(dayOfMonth / 10 + 0x30));      
  Serial.print(char(dayOfMonth % 10 + 0x30));
  Serial.print("/");
  Serial.print(char(month / 10 + 0x30));
  Serial.print(char(month % 10 + 0x30));
  Serial.print("/");
  Serial.print("20");
  Serial.print(char(year / 10 + 0x30));
  Serial.print(char(year % 10 + 0x30));          
  Serial.print("    ");
  Serial.print( char( hour / 10 + 0x30) );
  Serial.print( char( hour % 10 + 0x30) );
  Serial.print(":");
  Serial.print( char(minute / 10 + 0x30));
  Serial.print( char(minute % 10 + 0x30));
  Serial.print(":");
  Serial.print(char (second / 10 + 0x30));
  Serial.println(char (second % 10 + 0x30));
  Serial.println("\n\n\n");

  
  
  
  doubleToHrMin(fajr, hours, minutes);
 if (hours>hour&&PS==true) 
  {
    if(hours==hour && minutes>minute)
    {x=1; PS=false; }
    else if(hours==hour && minutes<=minute)
    {}
    else
    {x=1;   PS=false; Prayer="Fajar"; hrs=hours; mts=minutes;} 
     }
 
  Serial.print("Fajr ");
  Serial.print(hours);
  Serial.print(":");
  Serial.print(minutes);
  Serial.println();

 if (PS==true)
 { 
  doubleToHrMin(zuhr, hours, minutes); 
 if (hours>hour&&PS==true) 
  {
    if(hours==hour && minutes>minute)
    {x=2; PS=false; }
    else if(hours==hour && minutes<=minute)
    {}
    else
    {x=2;   PS=false; Prayer="Zohar"; hrs=hours; mts=minutes;} 
     }
   
  Serial.print("Zuhr ");
  Serial.print(hours);
  Serial.print(":");
  Serial.print(minutes);
  Serial.println();
 }   
 if (PS==true)
 { 
  doubleToHrMin(asr, hours, minutes);
 if (hours>hour&&PS==true) 
  {
    if(hours==hour && minutes>minute)
    {x=3; PS=false; }
    else if(hours==hour && minutes<=minute)
    {}
    else
    {x=3;   PS=false; Prayer="Asar"; hrs=hours; mts=minutes;} 
     }
   
  Serial.print("Asr ");
  Serial.print(hours);
  Serial.print(":");
  Serial.print(minutes);
  Serial.println();

 }   
 if (PS==true)
 { 
  doubleToHrMin(maghrib, hours, minutes);
 if (hours>hour&&PS==true) 
  {
    if(hours==hour && minutes>minute)
    {x=4; PS=false; }
    else if(hours==hour && minutes<=minute)
    {}
    else
    {x=4;   PS=false; Prayer="Magrib"; hrs=hours; mts=minutes;} 
     }  
     
  Serial.print("Maghrib ");
  Serial.print(hours);
  Serial.print(":");
  Serial.print(minutes);
  Serial.println();

  doubleToHrMin(isha, hours, minutes);
 }   
 if (PS==true)
 {  
 if (hours>hour&&PS==true) 
  {
    if(hours==hour && minutes>minute)
    {x=5; PS=false; }
    else if(hours==hour && minutes<=minute)
    {}
    else
    {x=5;   PS=false; Prayer="Isha"; hrs=hours; mts=minutes;} 
     }  
  
  Serial.print("Isha ");
  Serial.print(hours);
  Serial.print(":");
  Serial.print(minutes);
  Serial.println("\n\n");

  if (x==0)
  { doubleToHrMin(fajr, hours, minutes);
    x=1;   PS=false; Prayer="Fajar"; hrs=hours; mts=minutes;}
    Serial.print(x);
    //delay(5000);
 }
} 


bool Touch_getXY(void)
{
    TSPoint p = ts.getPoint();
    pinMode(YP, OUTPUT);      //restore shared pins
    pinMode(XM, OUTPUT);
    digitalWrite(YP, HIGH);   //because TFT control pins
    digitalWrite(XM, HIGH);
    bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
    if (pressed) {
        pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
        pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
    }
    return pressed;
}

void Initialize_Display()
{    uint16_t ID = tft.readID();
//    Serial.print("TFT ID = 0x");
//    Serial.println(ID, HEX);
//    Serial.println("Calibrate for your Touch Panel");
    if (ID == 0xD3D3) ID = 0x9486; // write-only shield
    tft.begin(ID);
    tft.setRotation(-1);            //PORTRAIT
    tft.fillScreen(BLACK);

  }

  void Read_Button()
  { bool down = Touch_getXY();
    Azaan_btn.press(down && Azaan_btn.contains(pixel_x, pixel_y));
    }

//convert Degree to Radian
double degToRad(double degree)
{ return ((3.1415926 / 180) * degree); }

//convert Radian to Degree
double radToDeg(double radian)
{return (radian * (180 / 3.1415926)); }

//make sure a value is between 0 and 360
double moreLess360(double value)
{ while (value > 360 || value < 0)
  {if (value > 360)
      value -= 360;
   else if (value < 0)
      value += 360; }
   return value;    }

//make sure a value is between 0 and 24
double moreLess24(double value)
{  while (value > 24 || value < 0)
  { if (value > 24)
      value -= 24;
    else if (value < 0)
      value += 24; }
   return value;   }

//convert the double number to Hours and Minutes
void doubleToHrMin(double number, int &hours, int &minutes)
{ hours = floor(moreLess24(number));
  minutes = floor(moreLess24(number - hours) * 60);       }

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{ return ( (val / 10 * 16) + (val % 10) );}

void calcPrayerTimes(int year, int month, int day,
                     double longitude, double latitude, int timeZone,
                     double fajrTwilight, double ishaTwilight,
                     double &fajrTime, double &sunRiseTime, double &zuhrTime,
                     double &asrTime, double &maghribTime, double &ishaTime)
{
  double D = (367 * year) - ((year + (int)((month + 9) / 12)) * 7 / 4) + (((int)(275 * month / 9)) + day - 730531.5);

  double L = 280.461 + 0.9856474 * D;
  L = moreLess360(L);

  double M = 357.528 + (0.9856003) * D;
  M = moreLess360(M);

  double Lambda = L + 1.915 * sin(degToRad(M)) + 0.02 * sin(degToRad(2 * M));
  Lambda = moreLess360(Lambda);

  double Obliquity = 23.439 - 0.0000004 * D;
  double Alpha = radToDeg(atan((cos(degToRad(Obliquity)) * tan(degToRad(Lambda)))));
  Alpha = moreLess360(Alpha);

  Alpha = Alpha - (360 * (int)(Alpha / 360));
  Alpha = Alpha + 90 * (floor(Lambda / 90) - floor(Alpha / 90));

  double ST = 100.46 + 0.985647352 * D;
  double Dec = radToDeg(asin(sin(degToRad(Obliquity)) * sin(degToRad(Lambda))));
  double Durinal_Arc = radToDeg(acos((sin(degToRad(-0.8333)) - sin(degToRad(Dec)) * sin(degToRad(latitude))) / (cos(degToRad(Dec)) * cos(degToRad(latitude)))));

  double Noon = Alpha - ST;
  Noon = moreLess360(Noon);

  double UT_Noon = Noon - longitude;

  ////////////////////////////////////////////
  //        Calculating Prayer Times       //
  //////////////////////////////////////////

  // 2) Zuhr Time [Local noon]
  zuhrTime = UT_Noon / 15 + timeZone;

  // Asr Hanafi
  //double Asr_Alt =radToDeg(atan(2+tan(degToRad(latitude - Dec))));
  double Asr_Alt = radToDeg(atan(1.7 + tan(degToRad(latitude - Dec))));
  // Asr Shafii
  //double Asr_Alt = radToDeg(atan(1 + tan(degToRad(latitude - Dec))));
  double Asr_Arc = radToDeg(acos((sin(degToRad(90 - Asr_Alt)) - sin(degToRad(Dec)) * sin(degToRad(latitude))) / (cos(degToRad(Dec)) * cos(degToRad(latitude)))));
  Asr_Arc = Asr_Arc / 15;
  // 3) Asr Time
  asrTime = zuhrTime + Asr_Arc;

  // 1) Shorouq Time
  sunRiseTime = zuhrTime - (Durinal_Arc / 15);

  // 4) Maghrib Time
  maghribTime = zuhrTime + (Durinal_Arc / 15);

  double Esha_Arc = radToDeg(acos((sin(degToRad(ishaTwilight)) - sin(degToRad(Dec)) * sin(degToRad(latitude))) / (cos(degToRad(Dec)) * cos(degToRad(latitude)))));
  // 5) Isha Time
  ishaTime = zuhrTime + (Esha_Arc / 15);

  // 0) Fajr Time
  double Fajr_Arc = radToDeg(acos((sin(degToRad(fajrTwilight)) - sin(degToRad(Dec)) * sin(degToRad(latitude))) / (cos(degToRad(Dec)) * cos(degToRad(latitude)))));
  fajrTime = zuhrTime - (Fajr_Arc / 15);

  return;
}


// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val / 16 * 10) + (val % 16) );
}

// Gets the date and time from the ds1307 and prints result
void getDateDs1307()
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  //Wire.write(0x00);
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  second     = bcdToDec(Wire.read() & 0x7f);
  minute     = bcdToDec(Wire.read());
  hour       = bcdToDec(Wire.read() & 0x3f);
  dayOfWeek  = bcdToDec(Wire.read());
  dayOfMonth = bcdToDec(Wire.read());
  month      = bcdToDec(Wire.read());
  year       = bcdToDec(Wire.read());

}

void setDateDs1307()
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(zero);
  Wire.write(decToBcd(second));    // 0 to bit 7 starts the clock
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));      // for 12 hour am/pm, need to set bit 6 (also need to change readDateDs1307)
  Wire.write(decToBcd(dayOfWeek));
  Wire.write(decToBcd(dayOfMonth));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));
  Wire.endTransmission();
}





void Alarm()
{    if (alarm==true)
{    alarm=false;
     myDFPlayer.volume(30);  //Set volume value. From 0 to 30
     myDFPlayer.play(1);  //Play the first mp3 
     tft.fillScreen(BLACK);  
     tft.drawFastVLine(180, 0, 10, WHITE);
     tft.fillCircle(180, 80, 70, MAGENTA);
     tft.fillRect(80, 80, 200, 140, CYAN);
     tft.drawFastVLine(45, 0, 15, WHITE);
     tft.fillCircle(45, 35, 20, MAGENTA);
     tft.fillRect(30, 55, 30, 165, CYAN);
     Azaan_btn.initButton(&tft, 180, 150, 200, 140, WHITE, CYAN, BLACK, " ", 2);
     Azaan_btn.drawButton(false);     
     showmsgXY(110, 160, 2, &FreeSans12pt7b, Prayer.c_str(), BLACK);
}
  }  




void Print_Time(int X, int Y,  String msg1,  String msg2, int COLOUR)
     {
     if (msg1!=Last_msg1)
     { 
     show_Digits(X, Y, 1, &FreeSevenSegNumFont, msg1, COLOUR); 
     Last_msg1=msg1;
     }
     showmsgXY(X+65, Y-10, 3, &FreeSans12pt7b, ":", COLOUR);
     if (msg2!=Last_msg2)
     {
     show_Digits(X+80,Y, 1, &FreeSevenSegNumFont, msg2, COLOUR); 
     Last_msg2=msg2;
     }
     }



void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg, int COLOR)
{
    int16_t x1, y1;
    uint16_t wid, ht;
    //tft.drawFastHLine(0, y, tft.width(), WHITE);
    tft.setFont(f);
    tft.setCursor(x, y);
    tft.setTextColor(COLOR);
    tft.setTextSize(sz);
    tft.print(msg);
    delay(100);
}

void show_Digits(int x, int y, int sz, const GFXfont *f, String msg, int COLOR )
{
    int16_t x1, y1;
    uint16_t wid, ht;
    //tft.drawFastHLine(0, y, tft.width(), WHITE);
    tft.setFont(f);
    tft.setCursor(x, y);
    tft.setTextColor(COLOR);
    tft.setTextSize(sz);
    tft.print(msg);
    delay(100);
}

Applications of Prayer Time Azan Alarm Device:

  • Personal home prayer reminder
  • Office or workshop prayer alert
  • Portable unit for travel
  • Islamic learning projects or Arduino teaching demos

Future Improvements

  • Add Bluetooth or Wi-Fi for remote time synchronization.
  • Enable volume adjustment via UI.
  • Hijri calendar support display.
  • Integration with a solar angle prayer time calculator.

Need This Project?

If you need this Project with or without Modifications or Customization then you can contact us through WhatsApp. We can deliver you this Project in the Following Ways.

Project Code:
we can provide you Project Code along with Zoom Assistant, through Zoom meeting for Setup of this Project or any other Arduino Project of your need.

Fully Functional Project with Hardware/Components Shipment:
if you can not make this project yourself then you can use this option. We will assemble the Project and will ship it to your Doorstep with Safe Packaging.

Learn More about the services we offer.

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
YouTube