Rough time of day needed for lighting timer

jusmee

Member
I need to turn lights on and off at certain times of day, and it doesn't need to be very accurate - within ten minutes or so is fine. So, I would rather not have to use a RTC chip for it.

Can this be done in software, even using the 'elapsed time' variable I see mentioned in the new 18 pin picaxe maybe?
 

hippy

Ex-Staff (retired)
All clocks will drift and software-based and non-crystal controlled clocks will drift more. If you have a means to regularly re-synchronise then that may get round the problem - A push button which you only push at 9:00pm when the evening news comes on say.

If the PICAXE internal clock is 2% out that could mean losing or gaining around half hour a day.

Other alternatives are counting 'mains cycles' or attaching a watch crystal directly to a PICAXE and coding it as an RTC.

The advantage of a proper RTC chip is that it can be more easily battery backed up so it doesn't forget time if the power does fail. If it's cost which concerns you then consider that against its advantages and effort of having to manually re-synch and reset after power-fail. In terms of 'cost for time involved' in avoiding an RTC a DS1307 will very likely work out to be cost effective.
 

premelec

Senior Member
Solar?

If you can tie to ambient external light you could reset after approximate time to when it gets light or dark watching an LDR or PV cell - that won't work if you need actual time...
 

Haku

Senior Member
Here's an off-the-wall thought; hook the picaxe into the piezo output of a cheap digital wristwatch set to beep every hour, this would enable the picaxe to keep track of time more accurately than it's own internal timer.

That is if the piezo signal can somehow be detected, picaxe ADC input?
 

jusmee

Member
If you can tie to ambient external light you could reset after approximate time to when it gets light or dark watching an LDR or PV cell - that won't work if you need actual time...
Lot's of great ideas and thoughts. This one may work particularly well, as the lights are for a reef aquarium. The organisms would probably benefit by having seasonal variations. I might even get to detect moonlight vs daylight vs cloudy day, and adjust the lighting to simulate that.
 

boriz

Senior Member
“certain times of day ... benefit by having seasonal variations”

If you want to synchronise to a local seasonal variation, then an external light detector is the obvious solution. If the fish would be more at home at a different latitude, then an external light detector is also the solution. Any clock solution would get out of phase eventually.
 

Jeremy Leach

Senior Member
If I was doing the ambient light idea I'd base the code around the transition from night to day, and use this 'edge' to synchronise.

The variation in light level during the day might be all over the place, but at night it's likely to be much steadier (unless you get car headlights etc).

You could take a rolling average of the light values - to filter out any brief spikes in light level. The more samples the average is over, the more definite the code can be about knowing if the state is 'night' or 'day', but the less well-defined the edge.

It's made me think of a project idea : If this worked well, then could have a lookup table of the ratio between day and night duration, and work out the date ! Maybe would need a PICAXE with resonator though. A sort of electronic sundial (think you'd need the table to be based on latitude).
 

hippy

Ex-Staff (retired)
There was a data logger which did this and some discussion on the forum. I think that was for long-term tracking of bird migration using the length of day / night and knowing the day to determine where in the world it was.

It's an interesting idea as once you have worked out what one or a few days are you know the next won't be much different to the last. First thing is probably to record light levels for a good duration of a few days at known times, then see how well you can extrapolate that data back to something meaningful and useful. Possibly easier to find 'midday' and 'midnight' though they won't coincide with 12:00 and 24:00.
 

eclectic

Moderator
There was a data logger which did this and some discussion on the forum. I think that was for long-term tracking of bird migration using the length of day / night and knowing the day to determine where in the world it was.

It's an interesting idea as once you have worked out what one or a few days are you know the next won't be much different to the last. First thing is probably to record light levels for a good duration of a few days at known times, then see how well you can extrapolate that data back to something meaningful and useful. Possibly easier to find 'midday' and 'midnight' though they won't coincide with 12:00 and 24:00.
http://www.picaxeforum.co.uk/showthread.php?t=14307&highlight=datalogger

e
 

jusmee

Member
If I was doing the ambient light idea I'd base the code around the transition from night to day, and use this 'edge' to synchronise.
That's what I had in mind.

The variation in light level during the day might be all over the place, but at night it's likely to be much steadier (unless you get car headlights etc).

You could take a rolling average of the light values - to filter out any brief spikes in light level. The more samples the average is over, the more definite the code can be about knowing if the state is 'night' or 'day', but the less well-defined the edge.
I need to take moonlight into account as well. Basically I need 3 states, day, night+moon, and night. Yes clouds etc will cause problems, even at night, but as this is driving lights in an aquarium, it won't be a disaster if it gets it wrong for a few hours.

It's made me think of a project idea : If this worked well, then could have a lookup table of the ratio between day and night duration, and work out the date ! Maybe would need a PICAXE with resonator though. A sort of electronic sundial (think you'd need the table to be based on latitude).
Electronic sundial? Yes, and given a date, you can set the actual time by looking up a table of sunrise/sunset times. Might be the small project I should start with, then use the learnings in the next one.
 
Top