How to improve date-time control from RTC? I want to run cameras at a remote site from external batteries as long as possible. I need power-miser Arduino to switch battery power on/off at set intervals (e.g. 5 min) during daytime only. I am a beginner with Arduino and electronics.

Have set up 'breadboard' arduino with mosfet module for switching the power supply and RTC module, both from Freetronics (http://www.freetronics.com.au/collections/modules/products/real-time-clock-rtc-module#.V-i-S8knuPs). Following their recommendation I'm using RTC library here: http://rweather.github.io/arduinolibs/index.html

I need to refine the crude hour-based script below. Weatherley library returns separate objects e.g date.day, time.hour etc. Is there a simple way to convert to date-time object? Then calculate sunrise and sunset times based on latitude? 

  #include &lt;JeeLib.h&gt; //  power saving library
  ISR(WDT_vect) { Sleepy::watchdogEvent(); } // Setup jeelip watchdog
  #include &lt;SoftI2C.h&gt; // rweather lib for RTC module 
  #include &lt;DS3232RTC.h&gt; //rweather lib for RTC module 
  SoftI2C i2c(A4, A5); // assign pins to SDA and SCL
  DS3232RTC rtc(i2c);
  RTCTime time;
  int gatePin = 12;   //  mosfet Gate connected to digital pin
  int startHour = 6; // want to replace with sunrise time 
  int endHour = 19; // want to replace with sunset time

void setup()
{
 pinMode(gatePin, OUTPUT);   //  output pin for mosfet module
}

void loop()
{ // main loop starts here
  rtc.readTime(&amp;time);  //get current time
  if (time.hour &gt;= startHour &amp;&amp; time.hour &lt; endHour) // check daytime
  {   // if condition begins here
      while(time.hour &lt; endHour ) // daytime operating period 

      {   //  while loop (day) begins here 
      digitalWrite(gatePin, HIGH);   // turn on gate for power supply 
      Serial.flush(); //needed before sleepy 
      Sleepy::loseSomeTime(30000); // low power wait
      digitalWrite(gatePin, LOW);    // turn off gate for power supply
      Serial.flush(); // needed before sleepy
      for (int i=0; i &lt;= 3; i++){
        Sleepy::loseSomeTime(65000); // low power wait
        } // end for loop
      rtc.readTime(&amp;time);   
      } // end while loop (day)    
      } //  if condition (daytime) ends here   
else
  { // else condition (night time) starts here
    while (time.hour &gt;= endHour || time.hour &lt; startHour ) 
    { // while loop (night) begins here
    for (int i=0; i &lt;= 59; i++){ 
    Serial.flush(); // needed before sleepy
    Sleepy::loseSomeTime(65000); // low power wait
    } // end for loop
    rtc.readTime(&amp;time); 
    } // while loop (night) ends here
// need to refine timing else hour-long wait periods can run past the end of night period
  } // else condition (night) ends here
} //  main loop ends here


I will be very grateful for advice, many thanks in advance!

EDIT: Part of my original question could be answered - see below about time-date format without using RTC. Issues with RTC appear harder than I expected. I think they will need a new question later.
Is there a simple way to convert to date-time object?


Not with this library. But you can find other
libraries supporting the DS3232 which work with the Arduino
Time library[]. This time library provides both the date and time in a
single object, either:


a time_t, which is just the number of seconds elapsed since a
standard “epoch”
a tmElements_t struct, which has the date and time broken into
separate elements (year, month, day, hour...).



  Then calculate sunrise and sunset times based on latitude?


There are quite a few algorithms describes on the Web for that. The more
accurate ones are also the more complex.


  #include &lt;SoftI2C.h&gt;


Doesn't your Arduino have a hardware I2C port? That would be more
efficient than software emulation.


  Serial.flush(); //needed before sleepy


It's only needed if you are actually using the serial port.

Edit: I saw on your other question that you have been bitten by
an incompatibility between the Arduino Time library and the file
time.h from avr-libc. Now I just noticed that avr-libc includes the
functions sun_rise() and sun_set() that you may find
handy. Not sure they will play well with the Arduino time libraries
though. One possible incompatibility is the fact that they use different
epochs for defining time_t (year 1970 v.s. 2000).