DS3231 RTC and Adafruits Lib

Hello my friends :slight_smile:
I got a problem using the DS3231 RTC. I used several libs but the return of the dates and time is not working exactly.

Pluged RTC modul to Arduino Nano.
Installed the Adafruit Lib.
Used the example Sketch for a test:

// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

RTC_DS3231 rtc;

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

void setup () {

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero


  delay(3000); // wait for console opening

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));

void loop () {
    DateTime now = rtc.now();
    Serial.print(now.year(), DEC);
    Serial.print(now.month(), DEC);
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(now.minute(), DEC);
    Serial.print(now.second(), DEC);
    Serial.print(" since midnight 1/1/1970 = ");
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);

Serial Monitor gives sometimes the right dates/the right time, but often i does not.

2018/8/13 (Monday) 15:15:48
 since midnight 1/1/1970 = 1534173348s = 17756d

2165/82/123 (Sunday) 146:142:5
 since midnight 1/1/1970 = 2038686829s = 23595d

2018/8/13 (Monday) 15:15:54
 since midnight 1/1/1970 = 1534173354s = 17756d

2165/82/123 (Sunday) 146:142:5
 since midnight 1/1/1970 = 2038686829s = 23595d

What am i doing wrong!!! Using an other Lib gave similar wrong results…

Tx for watching and tx for help :slight_smile:


I was using cheap wires. The female-header-wires seem not to fit very good. Changing the wires to better ones gave constant right results.

Freaky! Never had such problems, but that was the very last thing i could try.

So: If RTC gives back bullshit, remember me and change the wires :D

Thank u all!

but that was the very last thing i could try.

Once you fixed the problem, why would you need to try anything else?

remember me and change the wires

Or, do what you are supposed to do, and solder them in place.