# Arduino and DS1307 programming question

#### TrmickCO

Joined Oct 9, 2016
72
I'm still just messing around with this tinyRTC DS1307 learning how it does this and that. My question is: Is it ever permitted to use a "IF" statement like the one below with this RTC library? I figured I would experiment with just seeing if I could use the timer to turn on a LED at a specific hour, minute and second. It verifies, uploads fine. But, doesn't work. Any hint at some further reading is appreciated!
Code:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;
const int LED = 12;

void setup () {

// Configure pins A2 and A3 to provide power and ground
pinMode(A3, OUTPUT);
pinMode(A2, OUTPUT);
digitalWrite(A3, HIGH); // provides +5V
digitalWrite(A2, LOW);  // provides GND

Serial.begin(57600);
#ifdef AVR
Wire.begin();
#else
Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
rtc.begin();
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");

}
}

void loop () {
DateTime now = rtc.now();
delay(3000);
if ((now.hour()=='17')&&(now.minute()=='42')&&(now.second()=='11'))
{pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
delay(10000);
digitalWrite(LED, LOW);
delay(5000);}
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(5000);
}
As a side note- I know this DS1307 is not super accurate and in fact over two weeks it gained 8 minutes! Hooray
Just experimenting for future ideas.

#### Raymond Genovese

Joined Mar 5, 2016
1,658
Take a look at this statement:
if ((now.hour()=='17')&&(now.minute()=='42')&&(now.second()=='11'))

What does now.hour() return? That is, what type of variable? Hint, not two characters like '1' and '7'.

See how you print the value later?
Serial.print(now.hour(), DEC);

If you are curious, look in the library...
Code:
DateTime RTC_DS1307::now() {
Wire._I2C_WRITE((byte)0);
Wire.endTransmission();
uint8_t ss = bcd2bin(Wire._I2C_READ() & 0x7F);
uint16_t y = bcd2bin(Wire._I2C_READ()) + 2000;
return DateTime (y, m, d, hh, mm, ss);
}

Also, make sure you are running the clock in 24 hour mode not 12 hour mode?

xox

#### TrmickCO

Joined Oct 9, 2016
72
Take a look at this statement:
if ((now.hour()=='17')&&(now.minute()=='42')&&(now.second()=='11'))

What does now.hour() return? That is, what type of variable? Hint, not two characters like '1' and '7'.

See how you print the value later?
Serial.print(now.hour(), DEC);

If you are curious, look in the library...
Code:
DateTime RTC_DS1307::now() {
Wire._I2C_WRITE((byte)0);
Wire.endTransmission();
uint8_t ss = bcd2bin(Wire._I2C_READ() & 0x7F);
uint16_t y = bcd2bin(Wire._I2C_READ()) + 2000;
return DateTime (y, m, d, hh, mm, ss);
}

Also, make sure you are running the clock in 24 hour mode not 12 hour mode?
Thanks for the response and dealing with some super novice questions. First off, if my serial monitor is showing the 5pm hour as 17, does that indicate it is in 24 hour mode? Next I'm assuming the DEC is referring to decimal(BCD?) and that is something that is not actually printed in the serial monitor? I think I see where the values 1 and 7 wouldn't make sense to the clock.
What if I used something like this to first get the time into a string of numbers:

int nowMinutesSinceMidnight = (DateTime now.hour()*60)+ DateTime now.minute();

And entered those values into an "if" statement to control the LED?
I don't suppose this approach could possibly work?
I guess I don't quit grasp yet what the clock sees vs. what I see in the SM.
Some serious gaps in my knowledge still

#### Raymond Genovese

Joined Mar 5, 2016
1,658
Thanks for the response and dealing with some super novice questions. First off, if my serial monitor is showing the 5pm hour as 17, does that indicate it is in 24 hour mode? Next I'm assuming the DEC is referring to decimal(BCD?) and that is something that is not actually printed in the serial monitor? I think I see where the values 1 and 7 wouldn't make sense to the clock.
What if I used something like this to first get the time into a string of numbers:

int nowMinutesSinceMidnight = (DateTime now.hour()*60)+ DateTime now.minute();

And entered those values into an "if" statement to control the LED?
I don't suppose this approach could possibly work?
I guess I don't quit grasp yet what the clock sees vs. what I see in the SM.
Some serious gaps in my knowledge still
The short answer is to change the statement:
if ((now.hour()=='17')&&(now.minute()=='42')&&(now.second()=='11'))
to:
if ((now.hour()==17)&&(now.minute()==42)&&(now.second()==11))

and run it again.

Get the chip's data sheet (link here) and try to read it as best as you can. I personally find that I read many data sheets many times, each time I like to think that I get a greater understanding.

Keep in mind that there are three discrete parts to what you are doing 1) the chip, b) your Arduino code and c) the Arduino library code.

Your code is interacting with the chip through the library. Libraries can be great and easy and powerful, but many folks do not go into the library and actually look at the code to see how things are working. So, Figure 3 in the data sheet shows you how the chip's timekeeping registers are storing the time. The library is reading those registers and delivering elements of the time in a format that is convenient for your code.

Look at this statement in the library: uint8_t mm = bcd2bin(Wire._I2C_READ()); and look at how minutes are stored in figure 3 in the data sheet. Also search BCD (Binary coded decimal). The code in the library will return, to the calling program (your program when you use now.minute() ), an 8-bit unsigned integer (also called a Byte variable type in Arduino). This is why your comparisons always failed. The statement now.minute()=='42' will always fail because there is no 8 bit value uint8_t that can represent the characters '42'. But, the statement now.minute()==42 will be true when the returned value for minutes is 42 because an uint8_t can have a value of 42.

Notice that the library return has two other 'confusing' parts. First, you see Wire._I2C_READ(). That is for the program to actually read the chip's register using the I2C interface. Finally, there is the bcd2bin call. Without even looking, I can see that that function is going to take a BCD-coded value [look at Figure 3, note how ones of minutes is stored in bits 0-3 and tens of minutes is stored in bits 4-6 and bit 7 is always zero] and convert it to uint8_t. So, the function call takes the BCD coded value for minutes and converts it to a binary value that is returned...and eventually is sent to your program.

All that is probably going to be pretty confusing for a while, but if you keep at it and make liberal use of searches when you don't understand something, it will start to make sense.

#### shteii01

Joined Feb 19, 2010
4,644
Thanks for the response and dealing with some super novice questions. First off, if my serial monitor is showing the 5pm hour as 17, does that indicate it is in 24 hour mode?
Yes.
12pm+5pm=17

#### TrmickCO

Joined Oct 9, 2016
72
The short answer is to change the statement:
if ((now.hour()=='17')&&(now.minute()=='42')&&(now.second()=='11'))
to:
if ((now.hour()==17)&&(now.minute()==42)&&(now.second()==11))

and run it again.

Get the chip's data sheet (link here) and try to read it as best as you can. I personally find that I read many data sheets many times, each time I like to think that I get a greater understanding.

Keep in mind that there are three discrete parts to what you are doing 1) the chip, b) your Arduino code and c) the Arduino library code.

Your code is interacting with the chip through the library. Libraries can be great and easy and powerful, but many folks do not go into the library and actually look at the code to see how things are working. So, Figure 3 in the data sheet shows you how the chip's timekeeping registers are storing the time. The library is reading those registers and delivering elements of the time in a format that is convenient for your code.

Look at this statement in the library: uint8_t mm = bcd2bin(Wire._I2C_READ()); and look at how minutes are stored in figure 3 in the data sheet. Also search BCD (Binary coded decimal). The code in the library will return, to the calling program (your program when you use now.minute() ), an 8-bit unsigned integer (also called a Byte variable type in Arduino). This is why your comparisons always failed. The statement now.minute()=='42' will always fail because there is no 8 bit value uint8_t that can represent the characters '42'. But, the statement now.minute()==42 will be true when the returned value for minutes is 42 because an uint8_t can have a value of 42.

Notice that the library return has two other 'confusing' parts. First, you see Wire._I2C_READ(). That is for the program to actually read the chip's register using the I2C interface. Finally, there is the bcd2bin call. Without even looking, I can see that that function is going to take a BCD-coded value [look at Figure 3, note how ones of minutes is stored in bits 0-3 and tens of minutes is stored in bits 4-6 and bit 7 is always zero] and convert it to uint8_t. So, the function call takes the BCD coded value for minutes and converts it to a binary value that is returned...and eventually is sent to your program.

All that is probably going to be pretty confusing for a while, but if you keep at it and make liberal use of searches when you don't understand something, it will start to make sense.
So, to just get a fresh start I went ahead and reprogrammed the RTC(that thing was running way fast so I moved away any noise sources etc), checked all hardware and connections, and removed the apostrophes. Still verifies and uploads fine, but won't light the LED. Seems like such a simple thing, but still no luck. I wonder if I'm dealing with a hardware issue. I do intend to look into all the info you suggested when my eyes aren't burning from putting in too many hours at work, lol. Appreciate all the feedback though. Don't want to eat into too much of your time.

#### TrmickCO

Joined Oct 9, 2016
72
Yes.
12pm+5pm=17
Thanks! Just wanted to be sure the serial monitor (what I see) is what's happening on board.
Best

#### Raymond Genovese

Joined Mar 5, 2016
1,658
So, to just get a fresh start I went ahead and reprogrammed the RTC(that thing was running way fast so I moved away any noise sources etc), checked all hardware and connections, and removed the apostrophes. Still verifies and uploads fine, but won't light the LED. Seems like such a simple thing, but still no luck. I wonder if I'm dealing with a hardware issue. I do intend to look into all the info you suggested when my eyes aren't burning from putting in too many hours at work, lol. Appreciate all the feedback though. Don't want to eat into too much of your time.
On most Arduinos, pin 13 has an LED connected on board.

Unless you attached your own LED with a resistor to I/O 12 and gnd, I would try changing:
const int LED = 12;
to:
int LED = 13;

Let us know what happens.

Last edited:

#### TrmickCO

Joined Oct 9, 2016
72
On most Arduinos, pin 13 has an LED connected on board.

Unless you attached your own LED with a resistor to I/O 12 and gnd, I would try changing:
const int LED = 12;
to:
int LED = 13;

Let us know what happens.
Hi Raymond. Before I posted this on here, I started just there. Thought a perfect simple test was the onboard LED connected to 13. When that didn't work (same result), I thought I would try another output just to see what would happen. 12 was just a random choice. I didn't include the resistor because of the short duration. Wish I had another Arduino (Using Uno that came with a sensor kit) to see how it behaved. Oh well, I'm learning. Looking up things.
Also, (unrelated)when I decided to reprogram the RTC, I took some advice from the datasheet about interference/noise causing the clock to speed up. I would always unplug my USB cable from the PC (leaving the other end plugged into the Arduino) and lay it down- go about my day. Often it lay over RUNNING devices like a modem and other electronics. I wonder if that contributed to the speed increase. Acting as an antenna of sorts. Anyways, I digress lol.

#### TrmickCO

Joined Oct 9, 2016
72
Hi Raymond. Before I posted this on here, I started just there. Thought a perfect simple test was the onboard LED connected to 13. When that didn't work (same result), I thought I would try another output just to see what would happen. 12 was just a random choice. I didn't include the resistor because of the short duration. Wish I had another Arduino (Using Uno that came with a sensor kit) to see how it behaved. Oh well, I'm learning. Looking up things.
Also, (unrelated)when I decided to reprogram the RTC, I took some advice from the datasheet about interference/noise causing the clock to speed up. I would always unplug my USB cable from the PC (leaving the other end plugged into the Arduino) and lay it down- go about my day. Often it lay over RUNNING devices like a modem and other electronics. I wonder if that contributed to the speed increase. Acting as an antenna of sorts. Anyways, I digress lol.
Quick question to yourself and other Arduino folks: If you verify and load a sketch into the IDE without a hitch, what, in your experience are the odds the code is good to go?

#### Raymond Genovese

Joined Mar 5, 2016
1,658
Quick question to yourself and other Arduino folks: If you verify and load a sketch into the IDE without a hitch, what, in your experience are the odds the code is good to go?
Verifying ok means little more than the code compiles without an error. It says nothing at all about the fitness of the code to do anything.

What exactly is your set up beyond an Arduino Uno? Is the RTC on a shield or board or something that you built? Which library are you using? Can you be specific with the details?

Without the RTC attached, can you run the blink program successfully? Can you run the RTC successfully with the example sketches included in the library?

I think we can help you get this going, but we need the details - including a picture of how you have it set up if possible.

Divide and conquer.

Last edited:

#### TrmickCO

Joined Oct 9, 2016
72
Verifying ok means little more than the code compiles without an error. It says nothing at all about the fitness of the code to do anything.

What exactly is your set up beyond an Arduino Uno? Is the RTC on a shield or board or something that you built? Which library are you using? Can you be specific with the details?

Without the RTC attached, can you run the blink program successfully? Can you run the RTC successfully with the example sketches included in the library?

I think we can help you get this going, but we need the details - including a picture of how you have it set up if possible.

Divide and conquer.
Verifying ok means little more than the code compiles without an error. It says nothing at all about the fitness of the code to do anything.
That's what I'm looking for right there. Some input like that. That dividing line- look at hardware or software.
Everything runs fine with all sketches. No shields. Just a Uno plugged (USB) straight into the PC and the Arduino IDE loaded up. I just brought in the RTC library through the IDE and attempted to modify (what you saw). Simply put, as a learning experience with ideas in mind, I just wondered why this doesn't work?.... My background is just messing about with discrete components and circuits and decided to take a dive into programming with Arduino because of my interest in sensors.

#### Raymond Genovese

Joined Mar 5, 2016
1,658
That's what I'm looking for right there. Some input like that. That dividing line- look at hardware or software.
Everything runs fine with all sketches. No shields. Just a Uno plugged (USB) straight into the PC and the Arduino IDE loaded up. I just brought in the RTC library through the IDE and attempted to modify (what you saw). Simply put, as a learning experience with ideas in mind, I just wondered why this doesn't work?.... My background is just messing about with discrete components and circuits and decided to take a dive into programming with Arduino because of my interest in sensors.
It doesn't work now because you are not reading the clock often enough to catch it at the alarm time (in addition to the other points already mentioned). I will explain.

I dug up an old DS1307 board and ran your code and the monitor window looks like this:

Notice how it prints the time every 8 seconds?

I modified your program slightly (see below)
Code:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;
const int LED = 13;

void setup () {
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
Serial.begin(57600);
#ifdef AVR
Wire.begin();
#else
Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
rtc.begin();
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
}
}

void loop () {
DateTime now = rtc.now();
//delay(3000);
if ((now.hour() == 8) && (now.minute() == 16) && (now.second() == 11))
{
Serial.println("Alarm ON");
for (int x = 0; x < 20; x++) {
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
}
Serial.println("Alarm OFF");

}
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();

}
Now, the monitor output looks like this:

When it detects the target time - if ((now.hour() == 8) && (now.minute() == 16) && (now.second() == 11))
, it will print (to the serial monitor) "Alarm ON", and flash the onboard LED 20 times, and then print "Alarm OFF".

Try that.

Edited to add: If you are understanding why the one works and the other does not, consider your delay(xxx) statements. While in a delay using that statement, the program is not checking the time, it is basically just staying put. There are well known ways of avoiding the delay statement while continuing execution but checking if a particular interval has elapsed...but one thing at a time.

Last edited:

#### TrmickCO

Joined Oct 9, 2016
72
It doesn't work now because you are not reading the clock often enough to catch it at the alarm time (in addition to the other points already mentioned). I will explain.

I dug up an old DS1307 board and ran your code and the monitor window looks like this:
View attachment 148031
Notice how it prints the time every 8 seconds?

I modified your program slightly (see below)
Code:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;
const int LED = 13;

void setup () {
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
Serial.begin(57600);
#ifdef AVR
Wire.begin();
#else
Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
rtc.begin();
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
}
}

void loop () {
DateTime now = rtc.now();
//delay(3000);
if ((now.hour() == 8) && (now.minute() == 16) && (now.second() == 11))
{
Serial.println("Alarm ON");
for (int x = 0; x < 20; x++) {
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
}
Serial.println("Alarm OFF");

}
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();

}
Now, the monitor output looks like this:

View attachment 148032

When it detects the target time - if ((now.hour() == 8) && (now.minute() == 16) && (now.second() == 11))
, it will print (to the serial monitor) "Alarm ON", and flash the onboard LED 20 times, and then print "Alarm OFF".

Try that.

Edited to add: If you are understanding why the one works and the other does not, consider your delay(xxx) statements. While in a delay using that statement, the program is not checking the time, it is basically just staying put. There are well known ways of avoiding the delay statement while continuing execution but checking if a particular interval has elapsed...but one thing at a time.
Well, first off I just wanted to say thanks for looking into that. I'm stuck in a work routine until Tuesday or Wednesday. Just wanted to be clear I'm not brushing off your efforts so I wanted to make sure I shoot you a few lines.
The delay. Do you know how many times I wondered about that? Those weren't in there at first. When I very first tried this, it failed as I watched the SM speeding by the time I designated. So, I played around with delays a bit for the heck of it. First chance I get, I'm testing your code and getting back to you. I look forward to playing around with it actually.
Best

#### Raymond Genovese

Joined Mar 5, 2016
1,658
Well, first off I just wanted to say thanks for looking into that. I'm stuck in a work routine until Tuesday or Wednesday. Just wanted to be clear I'm not brushing off your efforts so I wanted to make sure I shoot you a few lines.
The delay. Do you know how many times I wondered about that? Those weren't in there at first. When I very first tried this, it failed as I watched the SM speeding by the time I designated. So, I played around with delays a bit for the heck of it. First chance I get, I'm testing your code and getting back to you. I look forward to playing around with it actually.
Best
Thanks for the note. When you think about it, it makes sense that it didn't work before you added the delays because you had the comparison wrong with:

if ((now.hour()=='17')&&(now.minute()=='42')&&(now.second()=='11'))

Then, after fixing that part, it didn't work because the delays were causing the program to miss the alarm time.

When you get a chance, you can run the new version and see if that works.

#### TrmickCO

Joined Oct 9, 2016
72
Thanks for the note. When you think about it, it makes sense that it didn't work before you added the delays because you had the comparison wrong with:

if ((now.hour()=='17')&&(now.minute()=='42')&&(now.second()=='11'))

Then, after fixing that part, it didn't work because the delays were causing the program to miss the alarm time.

When you get a chance, you can run the new version and see if that works.
It works!! At first, I got nothing on the serial monitor and the transmit light was off. I soon realized the only thing your code was missing was the analog input part in setup. It wasn't showing anything because well, it had no power. I popped that in there and it works great! This is the revised code (just added that section to the setup):
Code:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
const int LED = 13;
void setup () {
pinMode(A3, OUTPUT);
pinMode(A2, OUTPUT);
digitalWrite(A3, HIGH);
digitalWrite(A2, LOW);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
Serial.begin(57600);
#ifdef AVR
Wire.begin();
#else
Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
rtc.begin();
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
}
}
void loop () {
DateTime now = rtc.now();
//delay(3000);
if ((now.hour() == 19) && (now.minute() == 21) && (now.second() == 11))
{
Serial.println("Alarm ON");
for (int x = 0; x < 20; x++) {
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
}
Serial.println("Alarm OFF");

}
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
I see where I went wrong with actually delaying the clock as my target flew right on by. What was the comment you added referring to delay 3000?
So I went back to my original(ish) sketch and simply removed the delay from the serial print section. Leaving some delays within the conditions of that 'for' statement, figuring those delays will not hinder anything because a specific target only applies. It worked perfectly as well. Confirming, my "delay happy" fingers got me in the mess in the first place (or second place?)
Here's that code:
Code:
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;
const int LED = 13;

void setup () {
pinMode(A3, OUTPUT);
pinMode(A2, OUTPUT);
digitalWrite(A3, HIGH);
digitalWrite(A2, LOW);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
Serial.begin(57600);
#ifdef AVR
Wire.begin();
#else
Wire1.begin();
#endif
rtc.begin();
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");}}

void loop () {
DateTime now = rtc.now();
if ((now.hour()==19)&&(now.minute()==45)&&(now.second()==10))
{
digitalWrite(LED, HIGH);
delay(10000);
digitalWrite(LED, LOW);
delay(5000);}
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
Just wanted to say thanks for helping out...I'm learning a lot in the process!

#### Raymond Genovese

Joined Mar 5, 2016
1,658
/-- --/
Just wanted to say thanks for helping out...I'm learning a lot in the process!
Good deal and you are most welcome.

Edited to add: Almost missed your question "What was the comment you added referring to delay 3000?" I was just eliminating the delay statement from execution by putting the comment ("//" in front of the statement - removing it from execution but still letting you see its removal.

Also, I'm not sure if there is a specific reason why you are using two I/O pins to drive an LED - it can be done with one (see http://www.ladyada.net/learn/arduino/lesson3.html) for example.

Last edited:

#### Phil-S

Joined Dec 4, 2015
222
Have a look at some of the time related Arduino libraries like TimeAlarm and TimeLib (or very similar sounding names) that have a lot of useful timing and doing functions, all of which work well with the basic DS1307. Personally, I like the DS1307RTC library. When you want to up the accuracy, try the DS3231 compensated crystal controlled RTC clock chip in a small SOIC16 package. The 1307 library works with the DS3231.

#### TrmickCO

Joined Oct 9, 2016
72
Good deal and you are most welcome.

Edited to add: Almost missed your question "What was the comment you added referring to delay 3000?" I was just eliminating the delay statement from execution by putting the comment ("//" in front of the statement - removing it from execution but still letting you see its removal.

Also, I'm not sure if there is a specific reason why you are using two I/O pins to drive an LED - it can be done with one (see http://www.ladyada.net/learn/arduino/lesson3.html) for example.
I didn't realize I was... Not sure what to look at. I went back to look at the final code. Very possible I'm not seeing something!...This code is what I'm using to move ahead with an irrigation project of sorts:
Code:
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;
const int IRG = 13;

void setup ()
{pinMode(A3, OUTPUT);
pinMode(A2, OUTPUT);
digitalWrite(A3, HIGH);
digitalWrite(A2, LOW);
pinMode(IRG, OUTPUT);
digitalWrite(IRG, LOW);
Serial.begin(57600);
#ifdef AVR
Wire.begin();
#else
Wire1.begin();
#endif
rtc.begin();
if (! rtc.isrunning())
{Serial.println("RTC is NOT running!");}}

void loop ()
{DateTime now = rtc.now();
if ((now.hour()==10)&&(now.minute()==20)&&(now.second()==10))
{digitalWrite(IRG, HIGH);
delay(15000);
digitalWrite(IRG, LOW);}
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();}