Potentiometer & LDR controlled light timer.

The bear

Senior Member
Hi Everyone,

Help required please.

Object: An indoor automatic light timer. Using 14M2 driving a relay.

Light comes on at dusk/twilight via LDR & ADC, I'm OK with that.
What I would like to do, is have a potentiometer (Pot) to control the time it stays on, once switched, e.g. at dusk. the time period would need to be seven hours minimum, that would be long enough.
The seven hour period needs to be broken down into: 4 hr, 3 hr, 2 hr, 1 hr 30 min & 15 min.
I know that is more than seven hours, but by selecting certain times, all events will be covered, e.g. lengthening and shortening hours of daylight.

I have constructed one model, it uses six mini switches to select the time period/s.
This is done by reading the ADC from the LDR 'AND' switched output from 14M2,

Ideally if the Pot. ADC could be converted into time (Hours) I could
display this on the OLED. Time calc. is not critical +/- 5 mins.

I have searched the forum, but not found anything that I could modify to suit.
 

The bear

Senior Member
@ Tex,
If you are looking for perfection, don't look in my direction.
I know what I mean.
We require the light/s to go off about 11:00 pm whether we are at home, or out on the town.
Good to hear from you.
I'm really into symbols now, thanks for educating me.
Really enjoying Picaxe.
Regards, Bear..
 
Last edited:

The bear

Senior Member
Code:
	;Light timer Pot & Oled v1.0 29.01.17

	
	#Picaxe 08M2 ;14M2 ;20M2
	#No_Data
	#Terminal 4800
	#Com 3
	
	sertxd("Light timer Pot v1.0 29.01.17",13,10)
	
	Symbol Relay   = C.1 ;Output
	Symbol Potr  =  C.2 ;into b0
	Symbol LDR    =  C.4 ;into b4
;	Symbol (OLED 16 x 2) Axe 133 C.0
        Symbol counter = b2
Main:
		serout C.0, N2400, (254,1)
		pause 500
		ReadADC C.4, b4	;LDR
		pause 500
		ReadADC C.2, b0	;Potentiometer
		serout C.0, N2400, (254,128)
		serout C.0, N2400, (" TIME DURATION ")
		bintoascii b0,b1,b2,b3
	if b1 ="0" then ;Gets rid of the leading 0 from display
     		 b1 = " "
	endif
		pause 200
		serout C.0, N2400, (254, 192)      	
	
		serout C.0, N2400, (b1, b2, b3,  " Mins* x")
	if b4 <= 65 and b0 < 20 then
		High Relay
	For b2 =  1 to 6;0 ; Test
		pause 60;000 ;Test
	Next counter
	Endif
		goto Main
		
		;255 /60*14 = 59.5 ????
		
;From hippy	22.06.12	
;		ReadAdc POT, b0
;b1 = MAX_SERVO - MIN_SERVO * b0 / 255 + MIN_SERVO
;Servo SERVO_PIN, b1
 
Last edited:

techElder

Well-known member
I did something like the following on a pot that picked a script to play. I just figured out what the min and max readings were on the pot (sort of a percentage of range) and divided that up into the number of choices. In your case, you could select a time period instead of a script.

Rich (BB code):
readADC10 potADJUST, tempWord3
select tempWord3        ; select a script based on pot position with a range
      case 0 to 100
            ScriptNumber = 1
      case 101 to 200
            ScriptNumber = 2
      case 201 to 300
            ScriptNumber = 3
      case 301 to 400
            ScriptNumber = 4
      case 401 to 500
            ScriptNumber = 5
      case 501 to 600
            ScriptNumber = 6
      case 601 to 700
            ScriptNumber = 7
      else
            ScriptNumber = 0  ; selects current state and holds it
endselect
PS to The Bear: You were my best student! :D
 
Last edited:

PhilHornby

Senior Member
Another way...

Object: An indoor automatic light timer. Using 14M2 driving a relay.

Light comes on at dusk/twilight via LDR & ADC, I'm OK with that.
What I would like to do, is have a potentiometer (Pot) to control the time it stays on, once switched, e.g. at dusk. the time period would need to be seven hours minimum, that would be long enough.
The seven hour period needs to be broken down into: 4 hr, 3 hr, 2 hr, 1 hr 30 min & 15 min.
I know that is more than seven hours, but by selecting certain times, all events will be covered, e.g. lengthening and shortening hours of daylight.
I have a very similar project, but I cheated when it came to the time control aspect...

The project (08M2-based) is powered from an old mobile phone PSU, which is plugged into a simple (mechanical) mains timer. Within the project box, a 4700uF capacitor provides backup power when the timer switches off. The timer is on from about 16:00 (to cater for Winter in Northern England) to about 23:30 ish. This gives Dusk -> 23:30, with adjustments only required for Daylight Savings changes.

When power is applied, it starts monitoring the ambient light level - switching on my indoor lighting when it falls below a pre-determined level. It uses RF remote control (switching them on in a fancy pattern, naturally :)). It then enters a loop monitoring its own Power Supply voltage. When this drops below a preset value, it sends OFF commands to all the lights and continues to do so until the 4700 cap. has discharged.

(I wish I'd used the ADC to monitor the light level, instead of a preset pot and a logic-level input. It would have been easier to set up)

Update

In your case - using a relay, instead of RF - simply removing the power via an external timer, would switch off the lights. So no need for backup capacitors and PSU monitoring.
 
Last edited:

inglewoodpete

Senior Member
This is done by reading the ADC from the LDR 'AND' switched output from 14M2,

Ideally if the Pot. ADC could be converted into time (Hours) I could
display this on the OLED. Time calc. is not critical +/- 5 mins.
I used an 08M2 to work as a 24-hour clock, synchronised to sunset/dusk. It is accurate to within a few minutes a day. The timer is used to control lighting on an artwork that is mounted on the side of a public multistorey building. The client wanted the lights to turn on 45 minutes before dusk, off around midnight, on again an hour before dawn and off at down.

There are 1440 minutes in a day. The 08M2's internal 1-second "clock" is divided into minutes and is reset at dusk each day. An LDR faces West and does not seem to be affected by sunny or heavy cloud conditions - detection of sunset quite consistently. The length of the dark period (night time) is recorded for each night to allow calculation of the switching times during the different seasons. The 'clock' takes two sunsets to synchronise to solar time, since it needs to determine the current length of night.

If you need 15-minute increments, then you could use the (binary) value read from the potentiometer via ADC, where 15-minutes (%00000001) would be smaller increment. This would require a small change to your time-period breakdown to 5-bit binary values: 4h, 2h, 1h, 0.5h and 0.25h.

The attached chart logs the various components of my installation. It needs a little explanation:
  • The pink line shows the day/night status, as determined by the LDR and 08M2.
  • Red line is the LDR voltage, read by 8-bit ADC; the line has superimposed tick-marks showing switching times.
  • Blue line is the daily count of minutes (divided 5 for presentation in the chart).
  • Orange and green lines show evening and morning 'on' periods. The first morning 'on' time is a (software) guess, because the length of the night has not been determined yet.
  • The artwork lighting changes colour according to the direction of the wind - the grey line logs the wind direction at each 1-minute increment. (You can see that the wind drops to almost calm during the nights of the log period.)
3-Day Chart Software Vers.2.7.PNG
 

The bear

Senior Member
Thank you for your responses.

@ Tex, Looks promising, pity about your other students.

@ Phil, Clever, good use of existing 'stuff'. I could cheat, and use a mains time-switch to switch off at 11pm. But I would prefer a bit of variation, security wise.

@ IWP, I like the clock idea, I don't need 15 min. increments, just one, so the time period can be set to within 15 mins. of total time period.
Binary I find mucho difficult (Apologies to Besqueut), I cannot see how %00000001 = 15 mins, yet.

Regards, Bear..
 

inglewoodpete

Senior Member
Binary I find mucho difficult (Apologies to Besqueut), I cannot see how %00000001 = 15 mins, yet.
Not mucho difficult: just ignore the word 'binary'. If the ADC reading from the pot can be reduced to a 5-bit value** (0 to 31), and each of the 32 values represents increments of 15 minutes, then TimeSeconds = ValueADC x 15mins x 60secs or TimeSeconds = ValueADC x 900

** If the ADC reading from the pot can have a value between Vss (0v = 0) and Vdd(+5v = 255), then just divide it by 8 to make the range 0 to 31.

So, at the beginning of the time period, you take the 5-bit representative value and multiply it by 900 (a word result we'll call BearTime). At the start of your time period, reset the M2's system Time to 0 and wait for Time to equal BearTime. When Time = BearTime, do the action you want.
 

BESQUEUT

Senior Member
Binary I find mucho difficult (Apologies to Besqueut), I cannot see how %00000001 = 15 mins, yet.
May Beer God forgive you...
One bit is what you want it to be !
- 0V or 5V
- 0V or 3,3 V
- 0s or one second
- 0 mn or one minute
- 0 mn or 2 minutes
- 0 mn or 15 minutes
- an empty or a full pint of beer
-...

Then 10 can be :
- 30 minutes
- two pints of beer

Then 11 can be :
- 45 minutes
- 3 pints of beer

Is that is not absolutely clear, please drink the last one, and come back...
==> you now have 10 pints of beer...
OK ?
 

The bear

Senior Member
Thank you Everyone,
What a great forum.
I'm going to take a few extra painkillers, then study what you kind people have written.
@ Besqueut, I'm not into beer, so I will convert the pints into bars of dark chocolate (Using a word variable and a touch of binary).
BEARTIME, I like it. That will be my number one 'Symbol', thanks IWP, approved by Tex.

Regards, BearTime..
 
Last edited:

inglewoodpete

Senior Member
May Beer God forgive you...
One bit is what you want it to be !
- 0V or 5V
- 0V or 3,3 V
- 0s or one second
- 0 mn or one minute
- 0 mn or 2 minutes
- 0 mn or 15 minutes
- an empty or a full pint of beer
-...

Then 10 can be :
- 30 minutes
- two pints of beer

Then 11 can be :
- 45 minutes
- 3 pints of beer

Is that is not absolutely clear, please drink the last one, and come back...
==> you now have 10 pints of beer...
OK ?
I hope that any development using pints of beer is limited to byte variables. Even a 5-bit value (31) would represent a lot of beer:).
 

BESQUEUT

Senior Member
@ Besqueut, I'm not into beer, so I will convert the pints into bars of dark chocolate (Using a word variable and a touch of binary).
As said, one bit may be what you want !
Now I am sure that you have understood that !
More : I do not like beer at all ; I prefer dark chocolate and I am on your wavelength.
 
Top