# Wrong Date von RTC Module DS1302

**URL:** <https://forum.arduino.cc/t/wrong-date-von-rtc-module-ds1302/885815>\
**Category:** Programming\
**Created:** [July 16, 2021, 10:09am UTC](https://forum.arduino.cc/t/wrong-date-von-rtc-module-ds1302/885815 "2021-07-16T10:09:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![philipp1297](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@philipp1297](https://forum.arduino.cc/u/philipp1297)\
**Post date:** [July 16, 2021, 10:09am UTC](https://forum.arduino.cc/t/wrong-date-von-rtc-module-ds1302/885815/1 "2021-07-16T10:09:01Z")

</div>

Hello,  
im trying to get the actual date time printed in the serial Monitor.  
i used the following code for this:

```cpp
#include <virtuabotixRTC.h>

virtuabotixRTC myRTC(53, 52, 49);

void setup() {
  Serial.begin(9600);
  myRTC.setDS1302Time(00, 40, 11, 5, 16, 7, 2021);
}

void loop() {
  myRTC.updateTime();
  Serial.print("Date / Time: "); 
  Serial.print(myRTC.dayofmonth);
  Serial.print("/");
  Serial.print(myRTC.month);
  Serial.print("/");
  Serial.print(myRTC.year);
  Serial.print(" ");
  Serial.print(myRTC.hours);
  Serial.print(":");
  Serial.print(myRTC.minutes);
  Serial.print(":");
  Serial.println(myRTC.seconds);
  delay(1000); 
}

```

But the Output in the Serial Monitor is the following:

Date / Time: 45/25/2165 45:85:85  
Date / Time: 45/25/2165 45:85:85

I checked the battery. Still has the 3V.

What could cause this problem?

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [July 16, 2021, 10:24am UTC](https://forum.arduino.cc/t/wrong-date-von-rtc-module-ds1302/885815/2 "2021-07-16T10:24:23Z")

</div>

Which timezone/century are you in?

That library looks like it was written by someone unconvinced of the virtues of encapsulation.

I'd be inclined to put the time reporting code in its own function, and call it immediately after the set function in setup().

---

<div class="post-metadata">

**Author:** ![Danois90](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@Danois90](https://forum.arduino.cc/u/Danois90)\
**Post date:** [July 16, 2021, 11:50am UTC](https://forum.arduino.cc/t/wrong-date-von-rtc-module-ds1302/885815/4 "2021-07-16T11:50:25Z")

</div>

Looks like you've [got the code from here](https://surtrtech.com/2018/01/27/how-to-simply-use-ds1302-rtc-module-with-arduino-board-and-lcd-screen/). You may have got the wiring or pin numbers wrong.

---

<div class="post-metadata">

**Author:** ![philipp1297](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@philipp1297](https://forum.arduino.cc/u/philipp1297)\
**Post date:** [July 16, 2021, 12:26pm UTC](https://forum.arduino.cc/t/wrong-date-von-rtc-module-ds1302/885815/5 "2021-07-16T12:26:47Z")

</div>

I work with a Arduni Mega and used other Digital Pins. does it matter?  
It is a big Project and all the other pins are used.

---

<div class="post-metadata">

**Author:** ![Danois90](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@Danois90](https://forum.arduino.cc/u/Danois90)\
**Post date:** [July 16, 2021, 12:36pm UTC](https://forum.arduino.cc/t/wrong-date-von-rtc-module-ds1302/885815/6 "2021-07-16T12:36:14Z")

</div>

What I meant was that you should check if the pin numbers for CLK, DAT and RST are given correctly to the constructor of the used RTC class. If that is OK, there might be a conflict with some of the used pins so try different pins.

---

<div class="post-metadata">

**Author:** ![bezelsanddisplays](https://avatars.discourse-cdn.com/v4/letter/b/7ab992/32.png) [@bezelsanddisplays](https://forum.arduino.cc/u/bezelsanddisplays)\
**Post date:** [July 20, 2021, 10:32am UTC](https://forum.arduino.cc/t/wrong-date-von-rtc-module-ds1302/885815/7 "2021-07-20T10:32:35Z")

</div>

I have perhaps little concrete to add as I have not used that library.  
The library I do use has a different format, though. But as you are returning a dateTime, then you might be not retrieving the individual values correctly.

I wonder if it might word trying this:  
Change:  
Serial.print(myRTC.month);  
for  
Serial.print(myRTC.month());

and likewise for the other values

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [July 20, 2021, 12:33pm UTC](https://forum.arduino.cc/t/wrong-date-von-rtc-module-ds1302/885815/8 "2021-07-20T12:33:45Z")

</div>

Yeah no. Those are _variables_, which wouldn’t work too well called as _functions_.

You need to start over at square zero it seems. Wondering isn’t really a good approach.

Experiments have their place, why not try it and see exactly what kind of new ~~pain~~ problem it makes for you?

a7

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 17, 2021, 12:34pm UTC](https://forum.arduino.cc/t/wrong-date-von-rtc-module-ds1302/885815/9 "2021-11-17T12:34:15Z")

</div>

Closed on November 17, 2021, 12:34pm UTC

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