How to use the DS3231 Real Time Clock with Arduino

How to use the DS3231 Real Time Clock with Arduino

DS3231 Real Time Clock for Arduino


The DS3231 Real Time clock provides highly accurate information about time which contains hours, minutes and seconds, as well as, day, month and year information. Also, it has automatic compensation for leap-years and for months with fewer than 31 days.


Due to its low cost it is a good fit for every electronics projects where date and time is required. Other applications include Servers, Utility power meters, Telematics, GPS Systems, etc..


VCC – 5V

SCL – Analog Pin A5

SDA – Analog Pin A4


DS3231 Real Time Clock for Arduino


Note: Download the required library and follow these steps below:

Download the DS3231 library here:

Put the DS3231 folder in “arduino/libraries”.



/* Code for testing the DS3231 Real Time Clock
 *  Code taken from DS3231 library example 
 *  DS3231 library:
#include <DS3231.h>

DS3231 rtc(SDA, SCL);

void setup()
  // Setup Serial connection
  // Uncomment the next line if you are using an Arduino Leonardo
  //while (!Serial) {}
  // Initialize the rtc object
  // The following lines can be uncommented to set the date and time
  //rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014

// Code from the Demo Example of the DS3231 Library
void loop()
  // Send Day-of-Week
  Serial.print(" ");
  // Send date
  Serial.print(" -- ");
  // Send time
  // Wait one second before repeating
  delay (1000);


Open serial monitor to see day, date and time.