This is a real-time clock with the ability to show Gregorian date and daily prayer times. For this simple circuit, we need to use an Arduino UNO (or any Arduino board), an RTC DS1307 and NOKIA 5110 LCD.
You can buy the parts here (affiliate links):
- Arduino UNO
- DS1307
- NOKIA 5110 LCD
Arduino UNO
The Arduino Uno is an open-source microcontroller board based on the ATmega328P microcontroller. This board is equipped with sets of analog and digital GPIOs (General-purpose input/output) that may be interfaced to various sensors, actuators, expansion boards and other circuits.
The Arduino UNO has:
- 14 digital input/output pins (of which 6 can be used as PWM outputs)
- 6 analog inputs
- 16 MHz ceramic resonator
- 32 KB Flash Memory (0.5 KB used by bootloader)
- 2 KB SRAM
- 1 KB EEPROM
- DC Power Jack & USB Port
DS1307
The DS1307 serial real-time clock (RTC) is a low-power, full binary-coded decimal (BCD) clock/calendar.
The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year.
The DS1307 operates in either the 24-hour or 12-hour format with AM/PM indicator. It has a built-in power sense circuit that detects power failures and automatically switches to the battery supply.
Pin Function of the DS1307
- VCC, GND: DC power is provided to the device on these pins.
- SCL (Serial Clock Input): used to synchronize data movement on the serial interface.
- SDA (Serial Data Input/Output): SDA is the input/output pin for the 2-wire serial interface. The SDA pin is an open drain that requires an external pullup resistor.
- SQW/OUT (Square Wave/Output Driver): When enabled, the SQWE bit is set to 1, the SQW/OUT pin outputs one of four square wave frequencies (1Hz, 4kHz, 8kHz, 32kHz). The SQW/OUT pin is an open-drain and requires an external pull-up resistor. It will operate with either Vcc or Vbat applied.
- X1, X2: Connections for a standard 32.768kHz quartz crystal. The internal oscillator circuitry is designed for operation with a crystal having a specified load capacitance of 12.5pF
NOKIA 5110 LCD
Nokia 5110 LCD is an 84*48 pixels monochrome screen, it comes with a backlight and can be used to draw text, graphics or images. The LCD uses the PCD8544 controller (same used in the Nokia 3310 LCD), this controller interfaces to microcontrollers through a serial bus interface similar to SPI.
Nokia 5110 LCD Pinout
- VCC, GND: DC power is provided to the device on these pins.
- RST: it resets the display. It’s an active low pin. You can also connect this pin to the Arduino reset so that it will reset the screen automatically.
- CE (Chip Enable): an active low pin, it helps to select one of many connected devices sharing the same SPI bus.
- D/C (Data/Command): it tells the display whether it is receiving or displaying data. The HIGH signal is for data and the LOW signal for command.
- DIN: it is a serial data pin for the SPI interface, it will send the data from the microcontroller to the LCD.
- CLK (Clock): the LCD and the microcontroller will require a common clock to operate because of their SPI communication. this pin will help to make it.
- BL (Backlight): it controls the backlight of the display. You can control its brightness by adding a potentiometer or connecting it to a PWM-capable Arduino pin (Pin # 3, 5, 6, 9, 10 and 11).
You should adapt line 161 of the code:
calcPrayerTimes(year, month, dayOfMonth, 41.3, 20.6, 3, -18.5, -19, fajr, sunRise, zuhr, asr, maghrib, isha);
The parameters needed are:
- Longitude/Latitude/Time Zone of the desired place.
- Fajr Twilight/ Esha Twilight differ in calculations from one country to another.
You can also get the geographical coordinates of your city, such as latitude and longitude, which the program needs in order to calculate prayer times by visiting the IslamicFinder website then search for your city.
As we note in the image above, after I searched for the city of Cairo, prayer times appeared in addition to some information. What matters to us is latitude, longitude, Isha angle and Fajr angle, you will change those numbers in the program to suit your city.
How does the program work?The function takes the data of Year/Month/Day/Longitude/Latitude/TimeZone/FajrTwilight/IshaTwilight plus 6 references to double variables (Fajr/SunRise/Zuhr/Asr/Maghrib/Isha). These 6 variables are the ones to return data into. there are also some functions to help in some number conversions (for example, Radians to Degrees and vice versa).
So, if we take Cairo as an example:
- Longitude: 30.2
- Latitude: 30
- Time Zone: +2
- Fajr Twilight: -19.5
- Esha Twilight: -17.5
We should adapt line 161 like this:
calcPrayerTimes(year, month, dayOfMonth, 30.2, 30, 2, -19.5, -17.5, fajr, sunRise, zuhr, asr, maghrib, isha);
Note that these prayer times are still "double" and should be converted to a time format. Mahmoud Adly Ezzat made the doubleToHrMin function (you can find it before the calcPrayerTimes function) which splits the number into Hours and Minutes. It takes the double and two references to int variables.
Don’t forget to drop a thumb up if you find it useful.
P.S: the Prayer time calculation algorithm is written by Mahmoud Adly Ezzat. You can read more about it in his blog post.
Comments