Real Time clock module error-DS3231 This is not a code error I have been using DS3231 RTC module with battery. When I bought this module It worked perfectly now when I get it to use, The time is running perfectly. when I set the current time of my location, it has been running along with that time but the problem is when I unplug the power of my Arduino Nano and again when I give the power I can see the time is running from its start, I could not see any current time value my location but I have attached CR2032 battery along with DS3231 module? what is the problem with this? I changed another battery too but It shows same problem my DS32321 haven't kept the time when I unplug and re-plug the power
This is the code I'm using for set the time
#include &lt;DS3231.h&gt;

// Init the DS3231 using the hardware interface
DS3231  rtc(SDA, SCL);

void setup()
{
  // Setup Serial connection
  Serial.begin(115200);
  // Uncomment the next line if you are using an Arduino Leonardo
  //while (!Serial) {}
  
  // Initialize the rtc object
  rtc.begin();
  
  // The following lines can be uncommented to set the date and time
  rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
  rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014
}

void loop()
{
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(&quot; &quot;);
  
  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(&quot; -- &quot;);

  // Send time
  Serial.println(rtc.getTimeStr());
  
  // Wait one second before repeating :)
  delay (1000);
}

This is the code I'm using to make Interrupt
 #include &lt;DS3231.h&gt;

int Relay = 4;

DS3231  rtc(SDA, SCL);
Time t;

const int OnHour = 21;
const int OnMin = 46;
const int OffHour = 21;
const int OffMin = 48;

const int On2Hour = 14;
const int On2Min = 54;
const int Off2Hour = 21;
const int Off2Min = 48;

void setup() {
  Serial.begin(115200);
  rtc.begin();
  pinMode(Relay, OUTPUT);
  digitalWrite(Relay, LOW);
}

void loop() {
  Serial.println(&quot;Time:  &quot;);
  Serial.print(rtc.getTimeStr());
  Serial.print('\n');

  Serial.println(&quot;Date: &quot;);
  Serial.print(rtc.getDateStr());
  Serial.print('\n');

  t = rtc.getTime();
  Serial.print(t.hour);
  Serial.print(&quot; hour(s), &quot;);
  Serial.print(t.min);
  Serial.print(&quot; minute(s)&quot;);
  Serial.println(&quot; &quot;);
  delay (1000);
  //can be set lcd display alspo
  if(t.hour == OnHour &amp;&amp; t.min == OnMin){
    digitalWrite(Relay,HIGH);
    Serial.println(&quot;LIGHT ON&quot;);
    }
    
    else if(t.hour == OffHour &amp;&amp; t.min == OffMin){
      digitalWrite(Relay,LOW);
      Serial.println(&quot;LIGHT OFF&quot;);
    }
  if(t.hour == On2Hour &amp;&amp; t.min == On2Min){
    digitalWrite(Relay,HIGH);
    Serial.println(&quot;LIGHT ON&quot;);
    }
    
    else if(t.hour == Off2Hour &amp;&amp; t.min == Off2Min){
      digitalWrite(Relay,LOW);
      Serial.println(&quot;LIGHT OFF&quot;);
    }
}
I am posting a code please try it may be it can help you
    #include &quot;RTClib.h&quot;

RTC_DS3231 rtc;

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

void setup () {
  Serial.begin(57600);

#ifndef ESP8266
  while (!Serial); // wait for serial port to connect. Needed for native USB
#endif

  if (! rtc.begin()) {
    Serial.println(&quot;Couldn't find RTC&quot;);
    Serial.flush();
    abort();
  }

  if (rtc.lostPower()) {
    Serial.println(&quot;RTC lost power, let's set the time!&quot;);
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date &amp; time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date &amp; time, for example to set
    // January 21, 2014 at 3am you would call:
     rtc.adjust(DateTime(2020, 10, 19, 10, 13, 0));
  }

  // When time needs to be re-set on a previously configured device, the
  // following line sets the RTC to the date &amp; time this sketch was compiled
  // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  // This line sets the RTC with an explicit date &amp; 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('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(&quot; (&quot;);
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(&quot;) &quot;);
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

    Serial.print(&quot; since midnight 1/1/1970 = &quot;);
    Serial.print(now.unixtime());
    Serial.print(&quot;s = &quot;);
    Serial.print(now.unixtime() / 86400L);
    Serial.println(&quot;d&quot;);

    // calculate a date which is 7 days and 30 seconds into the future
    DateTime future (now + TimeSpan(7,12,30,6));

    Serial.print(&quot; now + 7d + 30s: &quot;);
    Serial.print(future.year(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.day(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();

    Serial.print(&quot;Temperature: &quot;);
    Serial.print(rtc.getTemperature());
    Serial.println(&quot; C&quot;);

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

Upload the above code and then upload the same code just comment the following part
if (rtc.lostPower()) {
        Serial.println(&quot;RTC lost power, let's set the time!&quot;);
        // When time needs to be set on a new device, or after a power loss, the
        // following line sets the RTC to the date &amp; time this sketch was compiled
        rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
        // This line sets the RTC with an explicit date &amp; time, for example to set
        // January 21, 2014 at 3am you would call:
         rtc.adjust(DateTime(2020, 10, 19, 10, 13, 0));
      }

This will work and even if you plug and unplug it from power the RTC time will not reset