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 <JeeLib.h> // power saving library
ISR(WDT_vect) { Sleepy::watchdogEvent(); } // Setup jeelip watchdog
#include <SoftI2C.h> // rweather lib for RTC module
#include <DS3232RTC.h> //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(&time); //get current time
if (time.hour >= startHour && time.hour < endHour) // check daytime
{ // if condition begins here
while(time.hour < 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 <= 3; i++){
Sleepy::loseSomeTime(65000); // low power wait
} // end for loop
rtc.readTime(&time);
} // end while loop (day)
} // if condition (daytime) ends here
else
{ // else condition (night time) starts here
while (time.hour >= endHour || time.hour < startHour )
{ // while loop (night) begins here
for (int i=0; i <= 59; i++){
Serial.flush(); // needed before sleepy
Sleepy::loseSomeTime(65000); // low power wait
} // end for loop
rtc.readTime(&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.