Timer: Progressive, add 2 mins per day.

The bear

Senior Member
Hi Everyone,

I would like to construct a timer that will ADD 2 mins. to a delay of say 30 mins. once every 24 hrs. So the next day the delay will= 32mins.

This is to control house lighting, comes on at dusk, goes off when the delay has timed out. The initial 30 mins delay would be for the longest day.

I would also require the timer to Subtract 2mins. each day, as the days get longer. The shortest day would require a delay of 6 hrs.

It will be controlled by a LDR, the plan is for the LDR to trigger the Picaxe to increment or decrement as required.

The hardware exists(CMOS), it has to be adjusted manually each week, as the days (Daylight) increases and decreases.
If successful it will replace the existing hardware.

Any pointers/ideas gratefully received.

Regards, Bear..
 

BESQUEUT

Senior Member
Not very clear for me...
What you said (for longuest day, IE shortest night=6h) :
Day 1 : at dusk, wait 30 mn then light ON, then wait 6h00mn, then light OFF
Day 2 : at dusk, wait 32 mn then light ON, then wait 5h58mn, then light OFF

1) if we start 2mn later, and wait 2mn minor each day, we switch OFF light at same hour...

2) Maybe you want to start your Picaxe at another date than winter solstice ?
==> so you have to enter the first timing . How will you do that ?

3) you will have to revert incrementation every solstice.

I suggest to also use dawn detect to keep track of the night length.
So you can automatically adjust yours timers.

NL=Night Length
DT=Dusk Timer
DT=NL/20
ON Timer=NL-DT-DT
 
Last edited:

rossko57

Senior Member
Trouble with using the sensor, it is susceptible to climate - overcast, sunny will shift the apparent dusk. OP has not specified if they want subjective or astronomical linkage.
 

BESQUEUT

Senior Member
Trouble with using the sensor, it is susceptible to climate - overcast, sunny will shift the apparent dusk. OP has not specified if they want subjective or astronomical linkage.
if correctly protected from artificial light and pointed to the North, an LDR can detect dusk and dawn with good reliability.
 

The bear

Senior Member
Hi BESQUEUT,
Thanks for the reply.

Not very clear for me...
What you said (for longuest day, IE shortest night=6h) :
Day 1 : at dusk, wait 30 mn then light ON, then wait 6h00mn, then light OFF
Day 2 : at dusk, wait 32 mn then light ON, then wait 5h58mn, then light OFF

1) if we start 2mn later, and wait 2mn minor each day, we swich OFF light at same hour...

2) Maybe you want to start your Picaxe at another date than winter solstice ?
==> so you have to enter the first timing . How will you do that ?

3) you will have to revert incrementation every solstice.,
Switching off at the same time each day is OK.

I could wait until the shortest day, to install it, with the delay of 30mins. adding 2mins per day for the next six months.

It would be OK until the shortest day, then it would be the time to start subtracting 2mins per day for the following six months.

It wouldn't be a problem to manually switch it from + to - Regards, Bear..
 
Last edited:

The bear

Senior Member
The LDR is working fine, as confirmed by the French Connection, thank you.
As stated the whole thing is working fine, using Cmos and manual adjustment.
The plan is to upgrade to Picaxe.
Very new to programming. Great system and a great forum.
Regards, Bear..
 

rossko57

Senior Member
I guess we're talking about a daylight extender for tropical fish or summat.
If you are happy with the LDR (fish would be) rather than astronomical accuracy, then exploit the LDR.
Like the man said, measure the the night length and decide how much time to add or subtract on the next night.

Which part of the code are you having trouble with? I guess you'll need to code a minute timer for calculations.
Perhaps begin by devising a night-length measure and save routine.

You might have to decide early on which Picaxe to use. Often that depends on in/out hardware needed. Sounds like you have LDR input and lights on/off output? Could be a job for 08M2. M2 series have convenient timer functions.
Is there any requirement or hardware for soft-dimming the light off, rather than a bang?
 

inglewoodpete

Senior Member
Solar-synchronised software timer

I wrote some daylight-synchronised clock software for an M2-series PICAXE. The "clock" counts minutes for each day (target = 1440) and is reset to zero at dusk each afternoon. Dusk is determined using an LDR and software. Dawn is recorded each day, to determine the length of days and nights. The internal "Timer" variable is used and has proven to be quite accurate. During testing and installation, the error when the Timer was reset was typically within +/- 3 minutes. Even I was pleasantly surprised!

The software is used to control lighting for the exterior of a multi-storey city building in the evenings (turning on 45 minutes before dusk) and again for 90 minutes before dawn - hence the need to record when dawn is expected.

Attached is a plot of the log taken during development. (The downward pointing 'spikes' on the red light level trace are timing events superimposed.) As you can see, the software can't anticipate dusk until 24 hours have passed!
3-Day Chart Software Vers.2.7.PNG
 

grim_reaper

Senior Member
I would personally approach this whole thing from a different angle. If you use a real time clock (RTC) chip in your circuit (I believe there are many posts covering topics on that) then your 'AXE will always know what time/day it is. Then you just need an algorithm or EEPROM lookup table of day number against on time and off time for that day. Simples :D
 

BESQUEUT

Senior Member
I would personally approach this whole thing from a different angle. If you use a real time clock (RTC) chip in your circuit (I believe there are many posts covering topics on that) then your 'AXE will always know what time/day it is. Then you just need an algorithm or EEPROM lookup table of day number against on time and off time for that day. Simples :D
Algorithm is not so simple... It depends from latitude and is lot of trigo calculations...
Better use a lookup table for week number 1>26 (27 > 52 are the sames...) and interpolate for dayly data.
You also need an interface to set current date/time.
 

inglewoodpete

Senior Member
Real time clocks have an inbuilt problem: they need checking and adjusting every few months. A solar-synchronised clock never needs adjusting.
 

hippy

Technical Support
Staff member
This is to control house lighting, comes on at dusk, goes off when the delay has timed out.
It might be worth describing what it is you actually want to achieve. As best I can tell having the lights come on at dusk and go off at 22:00 would seem to fit the bill.
 

The bear

Senior Member
Hello Everyone,
@rossko57, House lights, planning to use 08M2 . Just lights on--delay--lights off.
@IWPete, Too involved for a Bear
@grim-reaper, Might be 'Simples' for you, not into eeproms etc.
@Hippy, You are in the lead! Lights on at dusk and off at approx. 22:30 +/- 10mins.
I'm not sure how to add or subtract the 2mins. It's a case of add for 6 months, then switch to subtract for the following 6 months. (2mins per day). Thanks to all for your input.
 

techElder

Well-known member
Does the +/- 12 minutes make a difference in something, or are you just trying to be precise?

I'm thinking of maybe a rookery or incubator or ...
 

hippy

Technical Support
Staff member
I reckon you can probably calculate the length of the delay needed from measuring the time from dawn to dusk. Similar to what inglewoodpete has done.

No need for clocks or synchronisation and you can average out a few days to get a more accurate length. You can probably store previous data so it's still reasonably accurate even if it loses after dawn, usable if if loses power after dusk.
 

The bear

Senior Member
@ Texasclodhopper, House lights.
@Hippy, I don't need to calculate the length of the days. We are talking dark, we need our lights on from dusk to approx. 22:30hrs. each night.
This ranges from 6hrs in the depth of winter, to 30mins at the height of summer. It operates even if we are not at home.
I would like to upgrade the (CMOS) system to Picaxe.
As it is, it has to be adjusted weekly, by turning a pot.
Regards, Bear..
 

rossko57

Senior Member
@Hippy, I don't need to calculate the length of the days. We are talking dark, we need our lights on from dusk to approx. 22:30hrs. each night.
The suggestion about calculating (well, measuring really using the LDR) the length of daylight is not an end in itself. It's using the Picaxe as a self-correcting sundial. If it knows how long the day is, it can have a good stab at how long after dusk 22:30 falls. Which, from how you've described it, is what you are really interested in ? (rather than worrying about how to add or subtract 2 mins)

P.S what no-one seems to have thought about is daylight saving time - does that affect you, what is the behaviour you want then?

P.P.S you probably could replicate the behaviour of the existing CMOS exactly. The suggestions here are to exploit the power of the picaxe to deliver what you actually want for an end result, in a better way.
 

The bear

Senior Member
@rossko,
The suggestion about calculating (well, measuring really using the LDR) the length of daylight is not an end in itself. It's using the Picaxe as a self-correcting sundial. If it knows how long the day is, it can have a good stab at how long after dusk 22:30 falls. Which, from how you've described it, is what you are really interested in ? (rather than worrying about how to add or subtract 2 mins)
I am worrying about the adding & subtracting the 2 mins. Obviously not at the same time. That is the question I'm asking for help.

P.S what no-one seems to have thought about is daylight saving time - does that affect you, what is the behaviour you want then?
Good point! On the existing system, I would turn the pot. forward or backwards 1 hour. For now, I would like to crack the 2 minute barrier.
Code:
#Picaxe 08M2
main:			;State of play, Very poor.

label_01:
COUNT 2, 2000, w0
w0 = w0+1
		if pinc.3 = 0 then label_01
				;let b2 = 2000	;2secs
label_02:		

 		readadc 4,b1
		if b1 < 70 then gosub lighton
		goto label_01
lighton:
		high 1
		pause 5000	;5secs
		;pause b2 
		low 1
		return
 

hippy

Technical Support
Staff member

rossko57

Senior Member
@rossko,
I am worrying about the adding & subtracting the 2 mins.
Are you sure about that? I thought want you _really_ wanted was lights-off at 22:30?
Its nit-picking, but trying to differentiate ends from means. You can get bogged down in one set of means, but they may not the only or the best means.

You haven't said explicitly, but I think your requirement is to deal with daylight saving time change by using the "new" 22:30 as your target.
I think that rather torpedoes the sundial approach - it could be used to calculate approximate date in the year, but is only going to get within a couple of days of clock-changing day at best.
That is assuming the whole exercise is to avoid knob twiddling or button pushing?

I am now leaning to use an RTC - a specialist external clock/calender device - because of accurate date for DST purposes.
That would make lights-off at 22:30 trivial !
 

inglewoodpete

Senior Member
Does the timer have to be fully automatic or (like with the present timer) will you be around to flick a switch to swap between summertime and wintertime?

Also, is there a really strict reason why the lights must go off at 22:30 and not an hour earlier/later?

Thankfully, where I live we don't have to run around changing all our clocks twice a year:).
 

The bear

Senior Member
Hi Everyone,
Thanks to all for your suggestions.
The length of night is 24 hours less length of day and it seems to me there is a relationship between length of day and dusk to 22:30 -
Hippy, my apologies. I need to grow up, I'm only 73 (Second childhood).
@IWPete, we go to bed around that time of night, I agree, it would be better staggered a little.
I have several simple projects running (08M2's). Rain alarm, auto Venation blinds (4). I will give the timer a rest for now. Need to learn more about the Picaxe system.
Regards, Bear.. PS, I will be back!
 
Last edited:

inglewoodpete

Senior Member
I will give the timer a rest for now. Need to learn more about the Picaxe system.
Regards, Bear.. PS, I will be back!
Please stay! The PICAXE system is great for people of any age to learn with. I am well past my school days too but still learning.

I bought an AXE092 Schools Experimenter board (08M, now upgraded to 08M2) nearly 10 years ago. It is a wonderful self-contained board, with LDR, input pushbutton switch, peizo sounder, 3 LEDs and an interface to expand to a breadboard if you need to. These days, most of my projects use the larger PICAXE chips but if f I need to try out a new code concept, this is where I often start.
AXE092-1.jpg
 

The bear

Senior Member
@BESQUEUT,
Thank you for the prompt.
Did you manage to see the partial eclipse?
We did.

Regards, Bear..
 
Top