Contents

Interfacing DS3231 Real Time Clock RTC Module with Arduino

DS3231 RTC Module Features

DS3231 real time clock module features high accuracy and low power consumption. This RTC module maintains seconds, minutes, hours, day, date, month, and year information. In this module, the date is set based on whether the month is 29, 30 or 31 days, and also whether it is leap year or not. This module can be used in 12-hour and 24-hour formats.

Note

The DS3231 module is available in two different types on the market. There is actually no difference between the two types in terms of functionality and operation, and only the appearance and pin assignments are different.

DS3231 RTC Module Pinout

Two types of DS3231 RTC modules are available in the market. One of the types of the DS3231 RTC module has 6 pins:

  • INT: interrupt output
  • COT: Clock output
  • SCL: Serial Clock Input for I2C protocol
  • SDA: Serial Data Input / Output for I2C protocol
  • VCC: Module power supply – 5V
  • GND: Ground

You can see the pinout of this module in the image below.

The other type of the DS3231 module has 5 pins:

  • VCC: Module power supply – 5 V
  • SCL: Serial Clock Input for I2C protocol
  • SDA: Serial Data Input / Output for I2C protocol
  • NC: Not used
  • GND: Ground

You can see the pinout of this module in the image below.

Required Materials

Hardware Components

Arduino UNO R3 × 1
DS3231 I2C Real Time Clock RTC Module × 1
DS3231 Real Time Clock RTC Module for Arduino & Raspberry Pi × 1
Male to Male jumper wire × 1

Software Apps

Arduino IDE

Interfacing DS3231 RTC Module with Arduino

Step 1: Circuit

The following circuits show how you should connect Arduino to DS3231 module. Connect wires accordingly.

Step 2: Installing Library

From this part, everything is the same for both types of the DS3231 RTC module. Download the DS3231_library from the link below. Then, go to “Include Library” and install it.

Note

If you need more help with installing a library on Arduino, read this tutorial: How to Install an Arduino Library

Step 3: Code

Upload the following code to your Arduino. Then, open Serial Monitor.

   /*  
modified on Nov 22, 2020
Modified by MehranMaleki from Arduino Examples
Home
*/ #include <Wire.h> #include <ds3231.h> struct ts t; void setup() { Serial.begin(9600); Wire.begin(); DS3231_init(DS3231_CONTROL_INTCN); /*---------------------------------------------------------------------------- In order to synchronise your clock module, insert timetable values below ! ----------------------------------------------------------------------------*/ t.hour=3; t.min=0; t.sec=0; t.mday=14; t.mon=11; t.year=2020; DS3231_set(t); } void loop() { DS3231_get(&t); Serial.print("Date : "); Serial.print(t.mday); Serial.print("/"); Serial.print(t.mon); Serial.print("/"); Serial.print(t.year); Serial.print("\t Hour : "); Serial.print(t.hour); Serial.print(":"); Serial.print(t.min); Serial.print("."); Serial.println(t.sec); delay(1000); }

In this code, first, the time information including second, minute, day, month, year and century are set as the starting point and the module starts working and is updated every second. Then, every second, the information is received from the module and displayed in the Serial Monitor.

The output is as follows:

With these steps, you can easily interface the DS3231 RTC module with Arduino and utilize its precise timekeeping capabilities for your projects.

Liked What You See?​
Get Updates And Learn From The Best​

Comments (2)

  • lockie cresswell Reply

    Having no luck with my Pfc8563 modules I decided to try the DS3231 module instead. Using the code and library provided above I got the following output:
    00:50:31.427 -> Date : 14/11/2020 Hour : 3:0.0
    00:50:33.427 -> Date : 14/11/2020 Hour : 3:0.0
    00:50:35.416 -> Date : 14/11/2020 Hour : 3:0.0
    00:50:37.416 -> Date : 14/11/2020 Hour : 3:0.0
    00:50:39.446 -> Date : 14/11/2020 Hour : 3:0.0
    As you can see the seconds are not incrementing. I also noticed that the module runs extremely hot, too hot to touch.
    Any ideas?
    Thanks
    Lockie

    February 3, 2023 at 1:58 pm
    • Ali Abdolmaleki Reply

      Hi dear
      maybe any short circuit happened
      please check your connections like input supply pin with multimeter, to be sure don’t have short pins
      whats your supply adaptor? how much input voltage?

      February 28, 2023 at 1:57 pm

Leave a Reply

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