so i bought a DS3231 clock which i am using with This famous library .

// DS3231_Serial_Easy
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
// A quick demo of how to use my DS3231-library to 
// quickly send time and date information over a serial link
// To use the hardware I2C (TWI) interface of the Arduino you must connect
// the pins as follows:
// Arduino Uno/2009:
// ----------------------
// DS3231:  SDA pin   -> Arduino Analog 4 or the dedicated SDA pin
//          SCL pin   -> Arduino Analog 5 or the dedicated SCL pin
// Arduino Leonardo:
// ----------------------
// DS3231:  SDA pin   -> Arduino Digital 2 or the dedicated SDA pin
//          SCL pin   -> Arduino Digital 3 or the dedicated SCL pin
// Arduino Mega:
// ----------------------
// DS3231:  SDA pin   -> Arduino Digital 20 (SDA) or the dedicated SDA pin
//          SCL pin   -> Arduino Digital 21 (SCL) or the dedicated SCL pin
// Arduino Due:
// ----------------------
// DS3231:  SDA pin   -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin

#include <DS3231.h>

// Init the DS3231 using the hardware interface
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

void loop()
  // Send Day-of-Week
  Serial.print(" ");

  // Send date
  Serial.print(" -- ");

  // Send time

  // Wait one second before repeating :)
  delay (1000);

Now the problem is, after i set a time it shows the time and date perfectly until i cut the power of the DS3231. while being connected to my PC when i disconnected the power of DS3231, i see the timer getting reset while it should have recorded and continued the timer. It outputs 'Monday 1.1.2021 0.0.0'

Is it the problem of my module? or i am doinng something mistake here? or the module works in this way?

whenever i disconnect arduino power from PC, it still continues to count but whenever i disconnect DS3231 from 5 v pin of Arduino, it resets back. Does that mean that the DS3231 need to use the 16Mhz crystal from Arduino to function properly??

  • 1
    Is the battery on the module connected properly? Maybe you need to remove a piece of plastic that prevents that the battery getting depleted during storage.
    – PMF
    Jun 26, 2021 at 6:25
  • There was no plastic which prevent discharge. The RTC works fine while Arduino is powered off but all the pins of ds3231 are connected but, when arduino is off and 5v wire of ds3231 is disconnected, time resets. Jun 26, 2021 at 8:16
  • 1
    You didn't write what exact module you have. Normally, the battery and the RTC chip are on the same breakout board and therefore cannot be separated. Clearly, the RTC chip's 5V battery input voltage must stay connected.
    – PMF
    Jun 26, 2021 at 10:13
  • Yup. Show what you actually have.
    – timemage
    Jun 26, 2021 at 11:53
  • @PMF OK now, got it Jun 26, 2021 at 13:39

1 Answer 1


So you disconnect the 5V to the DS3231, but keep the SDA and SCL pins connected? By doing that, you are working outside of the recommended operating conditions.

If you leave the SDA and SCL pins connected, those pins will be at around 5V. The datasheet specifies that those pins shouldn't be higher that Vcc+0.3V. Where Vcc is 0V, in your case.

Removing power from the Arduino board will also remove the power from the I2C pins, keeping things within specifications.

  • Ok, understood. But if I separate scl sda and 5v gnd all from Arduino and reconnect them again to the arduino which is already powered on, will the timer still reset? Jun 26, 2021 at 13:37
  • 2
    @SubhaJeetSikdar try and see. Just note that you have to disconnect them in the right order. SDA and SCL first. Then Vcc. GND can stay connected. When re-connecting, go in the reverse order. So connect Vcc before SDA/SCL.
    – Gerben
    Jun 26, 2021 at 14:13
  • Thanks i got everything clear now. Jun 26, 2021 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.