DS1307 RTC UNO sample code, set time HOWTO use with serial

Hello,
I connected a DS1307 RTC to my Uno, it works, but I understand not all of the sample code and searching didn´t bring me to a result or solution, I know here are people who can halp me :wink:

What is this section for? I know it is for setting the time, but for what is the if?
RTC.get(rtc,true);
if(rtc[6]<12){
RTC.stop();
RTC.set(DS1307_SEC,1);
RTC.set(DS1307_MIN,27);
RTC.set(DS1307_HR,01);
RTC.set(DS1307_DOW,7);
RTC.set(DS1307_DATE,12);
RTC.set(DS1307_MTH,2);
RTC.set(DS1307_YR,12);
RTC.start();
}

And how can I set the time via serial input? What must be put in the console? Which format, in one line or one by one?

Serial.println(“SET TIME:”);
RTC.stop();
RTC.set(DS1307_SEC,rr[6]);
RTC.set(DS1307_MIN,rr[5]);
RTC.set(DS1307_HR,rr[4]);
RTC.set(DS1307_DOW,rr[3]);
RTC.set(DS1307_DATE,rr[2]);
RTC.set(DS1307_MTH,rr[1]);
RTC.set(DS1307_YR,rr[0]);
RTC.start();

Thank You!

Bye Herbert74!

Which RTC library are you using?

Try this.

http://bildr.org/2011/03/ds1307-arduino/

It is well-explained, and works.

rtc[6] stores the year. If it has a value less than 12, representing 2012, then it gets set up.