RTC and sunrise / sunset programming

Greatings to you all.
I'm planning a new project and I would like your help.
Using a RTC (DS1307 or RTC8564 if possible) the Arduino will calculate, using the sunrise library ( http://www.andregoncalves.info/ag_blog/?p=47 ) the sunrise and sunset in order to open and close that times a door.
Opening and closing the door lasts less than half a minute.
The rest of the day the Arduino has to sleep (or to be interrupted / alarmed by the 8564) in order to preserve energy.
The whole project will be powered by a battery charged by a solar panel (exists).
I would like your ideas to make a flowchart because all I can think of is a loop and the Arduino can't run 24/7.
Thanks

Now I'm using a 12V timer switch and I change sunrise / sunset manually once a week.

Forum member Nick Gammon has a great read on sleep:

Ray

Have you considered a photocell? It's cheaper & simpler, doesn't require programming, and doesn't rely on the accuracy of a clock.

I've used an X-10 system that was supposed to turn lights on/off at sunrise/sunset & sunset. The clock would drift (over several months) and their software had "issues" when combining automatic daylight savings time changes with the sunrise/sunset times. Of course, your software won't have these issues :wink: but a photocell solves everything.

I would like your ideas to make a flowchart because all I can think of is a loop and the Arduino can't run 24/7.

Why can't you run it 24/7?. A loop should work fine. Every time through the loop, you can check the current time and make sure the 'state" of the gate is correct for that time.

I've never used a RTC or interrupts with the Arduino, but I have a feeling it won't work unless the clock has an "alarm" feature built-in. You need to compare the actual current time with the target time, and I think the processor needs to be running (not sleeping) to do that.

Personally I would go along the lines of using a DS3231 RTC.

Connect the 'alarm out' of the 3231 to an interrupt. pin on the Arduino.

Set the alarm.
Go to sleep. (See Nick Gammons piece already referenced)
(Alarm activates the Arduino)
Do what needs to be done.
Set next alarm.
Go to sleep...

@mrburnette It's a great Topic Ray indeed.

@DVDdoug I used a photocell some months before (without Arduino) but it didn't work as I wanted. I couldn't adjust the variable resistor to the "darkness" I wanted, but with an Arduino it's probably a good idea.
It can't run 24/7 because I have and loads too (led lights about 7 hours at night in winter time) and the panel is only 30W.

@dannable The 3231 seems to be a good choice indeed.

If you use a standalone Atmega 328 it uses only 10mA when running at 16MHz but doing little or nothing. And if you run it at 8MHz (which is the default using the internal oscillator) it only consumes 6mA. These are 5V figures. They would be lower at 3V.

At these low power consumptions the complexities of sleeping may not be justified.

...R

DVDdoug:
Have you considered a photocell? It's cheaper & simpler, doesn't require programming, and doesn't rely on the accuracy of a clock.

This seems like the best approach to me. It's very easy to implement using a LDR.

If you take this approach I suggest you add some smoothing or 'debouncing' logic so that the door doesn't flap if somebody walks past or a cloud goes overhead during marginal lighting conditions.

Have you considered a photocell?

A photocell in combination with an RTC would seem like a good idea i.e. set time bands for sunset and for sunrise and then use the photocell within those timebands to decide when the event has ocurred. That solves issues of local geography (is the site in a valley or on a mountaintop) and also difficulties with light intensity (full moons, dark days, shadows from movable objects).

Thank you very much for your help.

If you are still interested in using the RTC8564, I just put up my library on Github, which may be of use.