DS3231 battery issues keeping time

I'm having issues with my RTC keeping time when I disconnect it. I'm using the non-rechargeable ones, that has the resistor and diode removed. But, when I measure the battery(CR2032), I'm at a steady 3.2-3.3v. I've even measured out all the smc's to verify they are receiving battery voltage. I've tried all the DS3231 library examples and even the RTClib's. None will keep the time when I disconnect power or reset the arduino mega. I've even tried a new unit just to make sure it wasn't that board. Still the same issue.

I don't know what to test next. I'm only using the sca/scl connections, plus power. Would any other connections help? My only other option is to build a 4 button box to manually input the time, when it comes to day light savings or a power loss.

Any thoughts?

Got GND connected?

Maybe your sketch is wrong? Are you sure you don't set the time to some fixed value in setup()?

Yes, I have ground connected. It's 4 connections I have all to the exact locations (currently 5v or 3v, grd, scl, sda). The board will run 3.3 or 5v. I've tried both and still the same results. I bought these from elegoo. Not sure their reputation.

I've been in component level maintenance for almost 15 years (circuit board repair on an everyday basis). Everything checks out board level. So something between board and software is the only thing I can think of.

I'm at a stand still. I'm willing to buy another brand if it's consistent. Boards are cheap. Just want it to work from an example from the manufacture level.

Thanks for the replys

Post minimum (non)working example of your sketch please. What means "none will keep time"? To which time it resets?

I've even measured out all the smc's to verify they are receiving battery voltage.

Here is a thread on a DS1307 failure to run on battery power with a counterfeit chip. It might be relevant to a DS3231.


3v to 3v on the board
Gnd to Gnd on the board
SCL to SCL on the board
SCA to SCA on the board

For the time...Even if it's plugged in and I reset the arduino it rolls back to when I initially compiled the program. To which it makes me think it's more of a chip issue.

Thanks for the link cattledog. Seems like that is possible. I'll just go with a known manufacture like adafruit.

I'll keep you guys posted when I get it in to see if it makes a difference.

.Even if it's plugged in and I reset the arduino it rolls back to when I initially compiled the program.

I over looked this statement, which indicates a code issue like Smajdalf mentioned. Please post the code. You may need to comment out an rtc setting section after the initial setting.

#include <Wire.h>
#include <DS3231.h>

DS3231 clock;
RTCDateTime dt;

void setup()

// Initialize DS3231
Serial.println("Initialize DS3231");;

// Set sketch compiling time
clock.setDateTime(DATE, TIME);

void loop()
dt = clock.getDateTime();

// For leading zero look to DS3231_dateformat example

Serial.print("Raw data: ");
Serial.print(dt.year); Serial.print("-");
Serial.print(dt.month); Serial.print("-");
Serial.print(dt.day); Serial.print(" ");
Serial.print(dt.hour); Serial.print(":");
Serial.print(dt.minute); Serial.print(":");
Serial.print(dt.second); Serial.println("");


That's the example code from the library. I've tried all 5 from the DS3231 library. All the same exact issue. I've also tried from the RTClib as well.

  1. Read "How to use this forum" to learn how to post code
  2. This line:
clock.setDateTime(__DATE__, __TIME__);

in setup() sets DS3231 time to compile time when the setup() function runs - that means on power up or reset of Arduino. You need to make it more clever. For example make a sketch that sets the time of DS3231 and then upload ANOTHER sketch without such capability.


You are 100% correct it was the clock.setDateTime. I'm still very new to C++. Found an example from adafruit and it worked.

Thanks so much for the help guys.