Arduino Digital Clock using DS3231 Pi Module

We are getting about how to make the digital clocks more accurate and precise even at varying parameters like temperature and humidity. Generally, in the market, if we go for buying the RTC module we will find the DS1307 module more simply. As DS1307 module is more prone to external temperature variation because it uses an external crystal oscillator circuit as a result the accuracy of the timekeeping changes. While designing a LED board for my college kec.edu.np, I suffered from a time accuracy problem. After a few days, time starts to vary from the original one. Thus, I decided to use a better RTC module that has an internal clock oscillator and I found the DS3132 Module.

Table 1: Major Difference Between DS1307 and DS3231

S.N. DS1307 S.N. DS3231
1. External Oscillator Clock Circuit 1. External Oscillator Clock Circuit
2. More prone to external temperature variation 3. External Temperature variation doesn’t affect much
4. Time Variation of about 5min / month 2. Time variation of about 2 min. / year

Due to the above reasons, DS3231 is superior to DS1207. The module I have used for making Arduino digital clock using is shown in figure 1. This module is designed for raspberry PI but also can be used with Arduino. In this tutorial, I am going to show how to interface the DS3231 module with Arduino.

ds3231 pi module

Checkout other clock and timer circuits posted on bestengineeringprojects.com 

  1. 24 Hour Digital Clock and Timer Circuit
  2. Digital Clock Circuit with Seconds and Alarm Time Display

Circuit Description: of Arduino Digital Clock using DS3231 Pi Module

The circuit of the Arduino digital clock using DS3231 shown in figure 2 is designed using very few components i.e. Arduino Uno Board, 16×2 LCD Module, and a DS3231 RTC module.

DS3231 uses SDA (Data Pin) and SCL (Clock Pin) only because of the I2C protocol. This module is designed to communicate using the I2C protocol. So, at first, find the SDA and SCL pin of your Arduino uno or compatible board. If you are using Arduino uno board pin A4 and A5 is SDA and SCL pin respectively. Similarly, if you are using Arduino mega pins 20 and 21 are SDA and SCL respectively.

Arduino Digital Clock using DS3231 Pi Module circuit diagram

So, connect the SDA or D pin of your RTC module to the SDA pin and the SCL or C pin to the SCL pin of your Arduino board. The Vcc pin of the RTC module can be connected to either +5V or +3.3V of your Arduino and the GND pin to the Ground (GND) pin of your Arduino.

Now, let’s talk about the LCD connection. For easy and better understanding I summarized the connection diagram in the bullet.

  • Pin 1 (Vss) of LCD to GND pin of Arduino
  • Pin 2 (Vcc) of LCD to +5V pin of Arduino
  • Pin 3 (VEE) of LCD to the wiper of 10K variable resistor as shown in the circuit diagram.
  • Pin 4 (RS) of LCD to digital pin D12 of Arduino
  • Pin 5 (R/W) of LCD to GND pin of Arduino
  • Pin 6 (E) of LCD to digital pin D11 of Arduino
  • Pin 7, 8, 9, and 10 (D0, D1, D2, and D3) were left unconnected.
  • Pin 11 (D4) of LCD to digital pin D7 of Arduino
  • Pin 12 (D5) of LCD to digital pin D6 of Arduino
  • Pin 13 (D6) of LCD to digital pin D5 of Arduino
  • Pin 14 (D7) of LCD to digital pin D4 of Arduino
  • Pin 15 (LED+) of LCD to +5V through current limiting resistor 330-ohm.
  • Pin 16 (LED-) of LCD to GND pin of Arduino

The connection of the hardware part is completed not let’s talk about the software part.

author prototype of arduino digital clock using ds3231

Software Code :

Software code for Arduino digital clock using DS3231 Pi module is written in Arduino programming language and compiled using Arduino IDE. Download the code from the below, and open it on your IDE.

You have to change a few code setups before uploading the code to your Arduino.

  • Open the code in your IDE
  • Scroll down to the void setup menu, where you see a few lines with comment

  • In setDS3231time() line you have to enter the current date and time in a predefined way. Like if you wish to inter 11:30:48Pm, Tuesday, 21st, August 2018 then you have to enter setDS3231time(48,30,23,3,21,8,18); As this is a 24hour clock format you have to use 23 for 11 pm and remove the connecting line from the function setDS3231time() as shown below.

  • Upload the code to your Arduino uno board. This is done to tell the DS3231 module to start the date and time from the above-set date and time.
  • Now, again you have to comment on that time setup line because if you are not doing so every time you interrupt the power supply the date and time it shows will be above the set date and time.

  • Again, upload the code with commented setDS3231time();

Making video of Arduino Digital clock using DS3231 Pi Model

Leave a Comment