RTC lost power let's set the time


I’ve got a problem with my project. When I send it to my arduino it says: RTC lost power let’s set the time.

Here is the code:

#include <LiquidCrystal.h>
#include <Wire.h>
#include “RTClib.h”

RTC_DS3231 rtc;

char daysOfTheWeek[7][4] = {“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”};

int Day;
int Month;
int Year;
int Secs;
int Minutes;
int Hours;

String dofweek; // day of week

String myDate;
String myTime;

// for the 16x2 LCD

#define rs 9
#define en 8
#define d4 7
#define d5 6
#define d6 5
#define d7 4
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup ()
lcd.begin(16, 2);
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!”);

// Comment out below lines once you set the date & time.
// Following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(DATE), F(TIME)));

// Following line sets the RTC with an explicit date & time
// for example to set January 27 2017 at 12:56 you would call:
// rtc.adjust(DateTime(2017, 1, 27, 12, 56, 0));

void loop ()
DateTime now = rtc.now();
Day = now.day();
Month = now.month();
Year = now.year();
Secs = now.second();
Hours = now.hour();
Minutes = now.minute();
dofweek = daysOfTheWeek[now.dayOfTheWeek()];

myDate = myDate +dofweek+ " “+ Day + “/” + Month + “/” + Year ;
myTime = myTime + Hours +”:"+ Minutes +":" + Secs ;
// send to serial monitor
//Print on lcd
myDate = “”;
myTime = “”;

Why do you think this is a problem?

Your code in setup() says

 if (rtc.lostPower()) {
   Serial.println("RTC lost power, lets set the time!");

so that is what it does.

When I send it to my arduino it says: RTC lost power let's set the time.

Then its just possible that the DS3231 has lost power perhaps ?

But why lost my RTC power?

I expect that the library call is looking at the OSF bit in the DS3231 for this status. From the datasheet

Bit 7: Oscillator Stop Flag (OSF). A logic 1 in this bit
indicates that the oscillator either is stopped or was
stopped for some period and may be used to judge the
validity of the timekeeping data. This bit is set to logic 1
any time that the oscillator stops. The following are examples
of conditions that can cause the OSF bit to be set:

  1. The first time power is applied.
  2. The voltages present on both VCC and VBAT are
    insufficient to support oscillation.
  3. The EOSC bit is turned off in battery-backed mode.
  4. External influences on the crystal (i.e., noise, leakage,
    This bit remains at logic 1 until written to logic 0.

The last sentence is why you keep getting this message.