Interfacing DS3231 Real Time Clock RTC Module with Arduino

Table of Contents

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

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.

Liked What you see?

Get updates and learn from the best

More To Explore

Leave a Reply

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