Triggering an output using RTC DS1307 and an Ardunio Uno R.3

Hello all

I am trying to control a dispensing operation using the RTC DS1307 and an Arduino Uno Rev.3

I have downloaded the RTClib however I am having troubles triggering the dispensing operation at certain times. I cannot find which command I can use to get the time from the RTC. My current code looks like this

void loop () {
    DateTime now = rtc.now();
   
    Hour = (now.hour(), DEC);
    
    if (Hour == 20) {
      digitalWrite (13, HIGH);

When I do this the value returned for Hour is in binary thus the trigger time of the 20th hour does not become true.

I will need to dispense at 8am and 6pm, additionally my dispensing operation will last for 10 seconds. How can I trigger the output high for 10 seconds without using a delay command.

Any help is appreciated

As I recall, the RTC returns everything as a BCD value that you must convert to decimal. If you look at the examples provided with the library, you should be able to get the time intervals you want. Look at Table 2, page 8, in:

http://datasheets.maximintegrated.com/en/ds/DS1307.pdf

for the contents of the clock registers. My guess is that the library examples will show how to retrieve the values you need.

greg3750:

    if (Hour == 20) {

That is the sort of code I use and should be fine in principle, but I use it for a single daily event, and I imagine you simply write the pin low after the required interval. At the moment, I assume it stays high for ever. I guess you need to make sure your gear works as a clock first

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

If you have a swag of these settings each day, you might look at the Time and Time Alarms library. I recall you can use it to make time windows, and might better suit your needs.

Did you tried this Library very useful

TimeAlarms Library, Run Functions At Specific Times and try it out

    Hour = (now.hour(), DEC);

Garbage. You are abusing the comma operator and assigning the value 10 to Hour. No wonder you can't get anything to happen when Hour is 20. It never will be.

Loose the outer parentheses and the stupid ", DEC" part. Just because ", DEC" was part of a Serial.print() statement does NOT mean that the parameters for Serial.print() can be used on other places.

Sorry for my ignorance, I am new to the C programming and thought that was the proper way to return a decimal value not specific to the serial print command.

I removed the excess and the program works exactly as intended. Thank you very much for your help!