Can't set correct time with rtc


I’m trying out the DS3231 rtc module.
I can’t seem to set the correct time. I’ve tried different libraries and the example codes from there.
I’ve tried both the IDE and the online version. All with the same result. Date is 2001.01.01 etc

Here’s an example code I’ve been trying:

#include "Sodaq_DS3231.h"
#include <Wire.h>
DateTime now;

void setup() {

    now =;
  uint32_t ts = now.getEpoch();
uint32_t old_timeStamp;

void loop() {
  now =;
  uint32_t ts = now.getEpoch();
  if (old_timeStamp == 0 || old_timeStamp != ts) {
    old_timeStamp = ts;
    int Nowyear = now.year();
    Serial.print(now.year(), DEC);
    Serial.print(now.month(), DEC);
    Serial.print(, DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(now.minute(), DEC);
    Serial.print(now.second(), DEC);
    Serial.print(' ');
delay (5000);

Example of the serial output:
2000/1/1 0:9:15
2000/1/1 0:9:20
2000/1/1 0:9:25
2000/1/1 0:9:30

Any Ideas?

Thanks for the reply. I am able to hard code the time using the code in the link. I was under the impression that the get Epoch function in my code was actually fetching the time via the pc. I see now that it was silly mistake... :slight_smile:
Will be adding an ESP later to connect to wifi, My thoughts are then to adjust time by fetching it from the wifi.
Thanks for the reply...

DS3231 is pretty accurate and you should not need to adjust it very often. If you use Internet Time, the DS3231 is probably redundant.