DS1307 not working

Hello, I need to have time information for a project and i'm using an RTC to get the time info but i couldn't get it to work, I tried a lot of codes online without any result, Same for the library sample code
the library sample code sends me 2000 for yyyy and always 0 for date and time
I've wired up all data pins to A0-A1-A2 and tried powering it using coin cell (3V) and arduino power, neither worked
I would appreciate any help thanks ! if you need anymore informations don't hesitate !

Try the following sketch which I have tested on DS1307 Breakout board (Fig-1):


Figure-1:

#include "RTClib.h"
#include<Wire.h>
byte lastReadSecond = 0;

RTC_DS1307 rtc;  //RTC_DS3231 rtc; //user data type RTC_DS3231    variable rtc or object
DateTime nowDT;

void setup ()
{
  Serial.begin(9600);
  rtc.begin();
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  rtc.adjust(DateTime(2024, 7, 12, 4, 21, 10));//set date-time manualy:yr,mo,dy,hr,mn,sec
}

void loop ()
{
  nowDT = rtc.now();
  if (lastReadSecond != nowDT.second())  //RTC has crossed 1 sec time
  {
    lastReadSecond = nowDT.second();
    showTime();
  }
}

//===================================================
void showTime()
{
  nowDT = rtc.now();  //nowDT hold Date and Time
//  lastReadSecond = nowDT.second();
  //---------------------------
  byte myHour = nowDT.hour();   //myHour holds Hour of time of daya
  if (myHour > 12)
  {
    myHour = myHour - 12;
  }
  Serial.print(myHour); //12:58:57     12:4:56
  Serial.print(':');
  //-------------------------------------------------
  byte myMin = nowDT.minute(); //to show leading zero of minute
   if (myMin < 10)
  {
    Serial.print('0');
  }
  Serial.print(nowDT.minute()); Serial.print(':');
  //--------------------------------------------------
  byte mySec = nowDT.second();
  if (mySec < 10)
  {
    Serial.print('0');
  }
  Serial.println(mySec);
}
//---------------------------------------------

Hey thanks for helping, although

 if (lastReadSecond != nowDT.second())

This part is never True, and if i get the showTime() function out it sends out this
09:09:14.015 -> 94:04:00
Maybe the problem is the board ?

You need this line to know when the RTC has crossed on second time and then update the time of the day.

I've noticed that yes but the lastReadSecond is never updated and therefor is always == to nowDT

Do you have any other DS1307 RTC or DS3231 RTC to try?

I'm considering changing board anyway yes, Thanks for the help tho
i'll try out a few of them it's not the most expensive board anyway

Well that sounds wrong to begin with.

Please read the forum guide in the sticky post and follow it. If you don't do that, you prevent us from helping you.

I think i will try to get a ne RTC, the one i use is quite old and i've heard DS3231 is better anyway
Sorry for the time loss

This is not time loss, but a part of process/work.

That's where lastReadSecond gets updated.

It would be more obvious done elsewhere

void loop ()
{
  nowDT = rtc.now();
  if (lastReadSecond != nowDT.second())
  {
    lastReadSecond = nowDT.second();
    showTime();
  }
}

But @hon38148lk will have the same issues with any I2C RTC if she does not wire it using SDA and SCL… on the UNO those are A4 and A5.

And what is the third data line?

a7

Right!

I delete the following line from showTime() and edit the original post as per above.

lastReadSecond = nowDT.second();

In order the pins are DS SCL SDA (VCC GND) But i see my mistake indeed thanks, I'll try this later on since i have to move on for now

@hon38148lk - until you want to use the temperature sensor that is on the module, just forget about DS.

You only need power, ground and the I2C lines.

If that does not work right away, there's one last subtlety.

We here.

a7

This is the circuit for DS1307 breakout board; where, you can clearly identify the pin signals. DS18B20 is the digital temperature sensor which does not come with the breakout board. There are PCB holes to place and solder the legs of the sensor. There is a non-volatile EEPROM (AT24C32) chip to store the times of the day.

These chips or modules aren't usually a problem.
Follow the guides and examples.
Yes, the DS3231 is better than the DS1307.
DS3231 without fine tuning achieves +/- 1 second a month against MSF60.
Highly accurate atomic clocks achieve +/- seconds in 40-billion years.
Staggering.

Really handy! You can always be exactly on time...

That is the circuit for some DS1307 breakout board.

It may be the very one @hon38148lk has in front of her right now, but it doesn't look anything like the several different DS1307 RTC modules I have in my lab.

If the module has the diode/resistor "charging" circuit, one of R5 and D1 should be removed.

See

https://campercontrol.devcave.uk/step-1-assembling-control-box/modifying-rtc-module/

a7

Where did you find that one i haven't been able to find it on spreadsheet i went trough

Hee: