Interface a DS3231 RTC Module with Arduino

What is a DS3231 RTC module?

It is a precise I2C based Real-Time Clock module which is integrated with a temperature compensated crystal oscillator(TCXO) and a crystal. It is low cost and extremely accurate RTC available as compared to other RTC IC. It provides such a high precision because the crystal oscillator is embedded inside the RTC IC due to which interference from surroundings like temperature, EMI does not affect the crystal. An onboard battery is also present on the module to maintain accurate timekeeping when the main power of the module is interrupted. It is very fast, uses bidirectional I2C serial communication at 4000kHz. It consists of 32Kb EEPROM and a 10-bit temperature sensor which has a resolution of 0.25 degrees Celsius.

Pin configuration of DS3231 RTC module

DS3231 RTC module pin diagram

Features of DS3231 RTC module

  • The operating voltage of DS3231 is 3.3 volts.
  • The operating temperature for commercial use is between 0°C to 70°C (for DS3232S) and for industrial use, it is between -40°C to 85°C (for DS3231SN). 
  • The digital temperatures output at an accuracy of ±3°C.
  • Low power consumption. 
  • The Real-Time Clock counts seconds, minutes, hours, day, date, month, and year with leap year compensation valid up to 2100

Components needed

  • Arduino UNO
  • RTC module DS3231
  • Jumper wires
  • Breadboard
  • 3 volts coin cell

Pin connections of DS3231 RTC module with Arduino

  • Connect the VCC pin of the RTC module to the 5-volt pin of the Arduino UNO board.
  • Connect the GND pin of the RTC module to the GND pin of the Arduino UNO board.
  • Connect the CLK pin of the RTC module to the A4 pin of the Arduino UNO board.
  • Connect the DATA pin of the RTC module to the A5 pin of the Arduino UNO board.

Circuit diagram of RTC module DS3231 with Arduino

DS3231 RTC module circuit diagram

Click to download DS3231 Library: http://www.rinkydinkelectronics.com/library.php?id=73
Please install this library in Arduino IDE otherwise you will get an error.

Arduino code for DS3231 RTC module

#include "DS3231.h" // Download this library from the link given below
DS3231  rtc(A4, A5); //Define SDA and SCL pin here
void setup()
{
  Serial.begin(115200); // Set baud rate for communication
  rtc.begin(); // Initiate RTC module
  
 //Uncomment the bellow code for setting day, date and time
  //rtc.setDay(MONDAY);    
  //rtc.setTime(13,2,2);     
  //rtc.setDate(2,5,2019);
}
void loop() { 
 
 Serial.print("Time:  ");
 Serial.print(rtc.getTimeStr()); // Use getTimeStr to get time from the RTC
 Serial.print("Date: ");
 Serial.print(rtc.getDateStr()); // Use getDatwStr to get date from the sensor
 delay(1000); 
}

Leave a Reply