DS3231 RTC issues

I am trying to set up a simple dosing pump setup for my reef tank and I am using an Arduino UNO connected to three 24V relays to control the pumps. I am then using a DS3231 RTC off of that that connects with an I2C LED screen.

I am using the RTC module in case the Arduino looses power I want it to be able to keep the time as it would be catastrophic if it dosed too much into the tank and kill everything. I installed the "uRTCLib" library by Naguissa to read the date and time. I was able to get it working sporadically using the following code:

#include "Arduino.h"
#include "uRTCLib.h"

// uRTCLib rtc;
uRTCLib rtc(0x68);

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup() {
  Serial.begin(9600);
  delay(3000); // wait for console opening

  URTCLIB_WIRE.begin();

  // Comment out below line once you set the date & time.
  // Following line sets the RTC with an explicit date & time
  // for example to set January 13 2022 at 12:56 you would call:
   rtc.set(0, 56, 12, 5, 13, 1, 22);
  // rtc.set(second, minute, hour, dayOfWeek, dayOfMonth, month, year)
  // set day of week (1=Sunday, 7=Saturday)
}

void loop() {
  rtc.refresh();

  Serial.print("Current Date & Time: ");
  Serial.print(rtc.year());
  Serial.print('/');
  Serial.print(rtc.month());
  Serial.print('/');
  Serial.print(rtc.day());

  Serial.print(" (");
  Serial.print(daysOfTheWeek[rtc.dayOfWeek()-1]);
  Serial.print(") ");

  Serial.print(rtc.hour());
  Serial.print(':');
  Serial.print(rtc.minute());
  Serial.print(':');
  Serial.println(rtc.second());

  Serial.print("Temperature: ");
  Serial.print(rtc.temp()  / 100);
  Serial.print("\xC2\xB0");   //shows degrees character
  Serial.println("C");

  Serial.println();
  delay(1000);
}

It was supposed to output looking like this:

but it looked like this after I update the time/date information:

Any help would be appreciated!

I forgot to add that I removed the part above where I inputted the time and date like it says to sorry.

What exactly is the problem? The output looks correct.

Perhaps obviously check that the RTC module has a fresh battery.

If it is a "safety critical" application (at least for the fish!), I would implement some code to check the sanity of the time from the RTC. Also check the Oscillator Stop Flag, and battery level would help.

Don't get confused by the date, the sketch prints it in the year/month/day format, so 25/2/18 is correct for February 18th, 2025.

The first image shows the serial monitor of IDE 1.x, the second one shows the serial monitor (and the code) in IDE 2.x. Is that what is confusing you?

You might need

  if (rtc.minute() < 10) Serial.print(0);
  Serial.print(rtc.minute());
  Serial.print(':');

For all other units too

1 Like

It was only sporadically working. I would say it worked 2-3 times out of close to 10 times I checked it. The other times it just kept saying date was 0/0/0 with a time of 0:00:00 without seconds going up

That is all Greek to me lol! I will research how to figure out how to display the battery status thanks for the tip!

That makes sense. My main issue is that it kept reverting to 0/00/00 and time 0:00:00

How do you have this all wired up? Sounds like something might not be a solid connection.

Can you clarify - when you get all the zeroes, does that mean the RTC clock has actually been reset to all zeros? Or does it go back to reporting the correct time if you run it again?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.