Smart picaxe outdoor light

newplumber

Senior Member
Hi
Has anyone built/seen a smart outside light, I guess i am sick of
doing jumping jacks to get mine to turn on and when it does turn on
it stays on for almost 4 minutes which i know I could easy buy a better one
but i thought why not make it picaxe smart.

I was thinking like this
using a microwave sensor and a real time clock
with a ldr for daylight turning off
with a SSR to turn the bright led bulbs on

so I would try to code the 20X2 picaxe so
it would stay on from dusk till midnight
after that it would use the sensor like normal out door lights do
then when dawn appears it stays off all day
just a thought anyway
your friend
 

Attachments

premelec

Senior Member
You're ready for the project! is there a solar charge panel too? And batteries that can take the ND winter temperature..? better find out... I'd use a 14M2 - nothing fancy - perhaps a sloppy internal clock that resets watching the sun - if there is any up there ;-0
 

lbenson

Senior Member
... jumping jacks ...
I know what you mean. I have one which is turned on by the headlights of passing cars (which is ok), and another which requires the dance routine.

I think premelec is right that you don't need the real time clock if you are using the ldr to sense dawn and dusk--internal timing should be sufficient for your on/off needs unless you need to be precise about midnight. So pin for LDR, pin for motion sensor, pin for SSR, pin for ... what else is there--maybe a job for an 08M2.

Hmmm, could be a long time between dusk and midnight in winter in SD--maybe you do need the RTC (and thus 14M2) for that task, though with the use of C.0 and C.5 you still might do it with an 08M2. (I know you have a collection of the 20x2s.)
 

newplumber

Senior Member
@ premelec .... solar charger? lol good idea but no ...I don't know much about solar power or (after reading the other post) battery power.
I have sadly dust on my 20m2s chips so I will use one of those
btw ND temperatures are not so bad ...its the wind.. and it causes farmers to gather their crops in the next 2 states


@ lance yes I probably wont need a real time clock but I have a lot of them and am very impressed at the accuracy so using Marks day light time code
or Allycats code for sunset a person could forget the LDR and turn the light on right on sunset and off at midnight then it would use the microwave sensor for the rest of the night
till like 2 hours before sunrise it would turn back on and then off from sunrise to sunset.
Another great/horrible idea is lets say after midnight a person like me is still up working on some project and when using
the micro sensor a person can program so the light to stay on like for 10 minutes and if the sensor is reactivated
during the 10 minutes then it would add another 20 minutes so the light would be on for a 1/2 hour.

I guess i do not know if the temperatures will cause the RTC to be off accuracy, if that will be problem I can use "easyheat" (best heat tape IMHO) in a insulated box
your off for the weekend friend
and thanks
 

The bear

Senior Member
Hi, I'm far from smart.
This small program uses a LDR to switch on the outside lights,
It's terminated by a mains timer, which also supplies the power via a step down power supply 5 volts.
The mains timer is set to come on well before dusk.
Code:
        ;Outside lights v1.2 15.03.17
		
	#Picaxe 08M2 ;14M2 ;20M2 92 Bytes
	#No_Data
	#Terminal 4800
	#Com 3
	
	sertxd("Outside lights v1.2 15.03.17",13,10)
	
	Symbol Relay = C.2 ;GreenLED
	Symbol LDR_sensor = C.4; into b6/b7
	;Symbol paus = w0 
	Symbol LIGHT_ADC =   b6 
	Symbol Standby = C.1  ;YellowLED

	;Let w0 = 60000
	let dirsC = %00000111
 Main:
Do			;From hippy	;Average in 20 secs
	  ReadAdc LDR_sensor, b6 ;w0
	  time = 0
 Do
	    ReadAdc LDR_sensor, b7
	    b6 = b6 + b7/2
	    pause 1000 
	   ; sertxd (#time)
Loop Until time >= 20	;20 secs
	  ;SerTxd( #b6, CR, LF )
		pause 100
		High Standby
		pause 200
	If LIGHT_ADC < 65 then	;Dusk
	;Loop until LIGHT_ADC < 65 
		Low Standby
		High Relay 	;Light ON, until Timeswitch powers OFF mains->
	Endif	
	;Endif				; OFF @ approx 22:30Hrs 
Loop
Regards, bear..
 

The bear

Senior Member
@ newplumber,
Mains timer is a standard, stand alone plug-in. No wires. Ldr's ORP12 ~ 0.5 in. dia. or the small ones ~ 0.25 in. dia. Either seem to last about the same time.
This is UK, 13 amp 3 pin sockets & plugs. I use the same LDR's that you listed, 5mm. Just got a few orp12's left.
Regards, bear..
 

AllyCat

Senior Member
Hi,

i am sick of doing jumping jacks to get mine to turn on and when it does turn on it stays on for almost 4 minutes
Yes, the advantage of a PICaxe system is that you can design and build it to do what you want. The ON time delay is very easy to change of course and you can select a suitable "light level" for the triggering/gating, but a common problem with "Solar Lights" is that they tend to switch on at too high a light level. Your LDR with (say) 10k in series, dividing the Vdd to an ADC input should allow setting to quite a low light level, or a sunrise/sunset calculation would allow even lower (nominal) light levels. For example "lighting up time" (for vehicles and street lamps) in UK used to be half an hour after sunset (which is quite dark), but now it is sunset and new cars have "all-time" lights anyway.

But your main choice can be in the "alarm" sensor, or combination of sensors: most of these are actually movement sensors, but they each have different characteristics. Doppler Radar sensors detect movement towards or away from the transmitter/receiver, particularly of metallic objects, so their range for people might not be very great. Passive Infra Red (PIR) sensors detect the "heat" (from people and some animals) moving sideways across the field of view of a series of "beams" created by their "Fresnel" Lens. Of course moving towards them may produce some effective sideways movement, and being "optical" they can have a good range, particularly with a (special) "corridor" Lens.

Then there is ultrasonics (e.g. as used for robot projects), which can detect the distance to static objects, but probably only up to about 15 feet range. Alternatively, an ultrasonic "field" can be set up in any enclosed space, like a room or car, to detect very small movements of almost anything.

Cheers, Alan.
 

newplumber

Senior Member
Okay thanks bear now I understand... Have you ever had problems with dirt/dust making your ldr confused? I guess even with a good cover and since mine would be
up in the most un conveniently way possible to clean..so I am trying to delete the ldr altogether


@ Alan
thanks.. now you have me juggling between my PIRs or my microwave sensors also i want very bright led flood lights that don't use much power lol
which is impossible but I was thinking like these
https://www.amazon.com/Bioluz-LED-PAR38-Equiv-Dimmable/dp/B01947HSHW/ref=sr_1_2?ie=UTF8&qid=1503443090&sr=8-2-spons&keywords=led+outdoor+flood+light&psc=1
I will draw up + add some crazy box design in a bit
plus I think it would be awesome to use your code of the sunset/sunrise times with a real time clock (ds3231)
I'll be back to add more useful (i hope) garbage
Mark

EDIT okay i have some what of my idea on paper
I will try to build the box out of stainless ( i can weld sometimes :) ) and because hail
is not my friend I would make a cover to protect the bulbs
and the sensor would be right below the bulbs outside of the ss box in some water tight contraption
its a thought anyway
 

Attachments

Last edited:

newplumber

Senior Member
HI
Sorry Allycat but your great code found here
http://www.picaxeforum.co.uk/showthread.php?30114-Sunrise-and-Sunset-calculation-using-an-08M2-)
is way over my head ...maybe someday I will be able to understand 25%
so I made this code instead using Marks snippet daylight savings code
Code:
'This code is for a smart outdoor light unprofessionally 
'uses a 20M2 chip and reads a ds1307 real time clock 
'also has a microwave sensor  or a PIR sensor on pin b.1
'also will control a SSR(solid state relay) on pin b.0
setfreq m4 

input b.1  ' motion sensor switch
input b.2  ' switch for lights on all nite (optional)   
 
 SYMBOL index        = b0  'w0   
 SYMBOL hours        = b1  'w0
 SYMBOL mins         = b2  'w1
 SYMBOL secs         = b3  'w1  
 SYMBOL day          = b4  'w2     
 SYMBOL date         = b5  'w2  
 SYMBOL month        = b6  'w3   
 SYMBOL year         = b7  'w3 
 SYMBOL CommonYear   = b8  'w4
 symbol counter      = b9  'w4   variable used during loop 
 symbol mask         = w5       'b10-b11 bit masking variable
 'symbol mask word   = b11
 symbol var_out      = w6       'b12-b13&#8216; data
 'symbol var_out     = b13      'b12-b13&#8216; data
 SYMBOL DayNumber    = W7
'SYMBOL DayNumber    = b15       b14-b15&#8216; data
 SYMBOL DSTstart     = W8
 SYMBOL DayS         = W8     '= b17   b16-b17&#8216; data
 SYMBOL DSTend       = W9  
'SYMBOL DSTend       = b19       b18-b19&#8216; data
 symbol on_off_hour  = b20
 symbol loopone      = b21
 symbol Ltime        = b22
'symbol              = b23
'symbol              = b24
'symbol              = b25
'symbol              = b26
'symbol              = b27 
 Ltime = 1    

'InitialiseTime:  
    'HI2Csetup I2Cmaster, %11010000, I2Cslow_32, I2Cbyte  ' Set  DS1307 to 100kbps 
      'HI2Cout $0 , ( $10, $56, $14,day, $25 , $08 , $17) ' program DS1307 with GMT 
        '             sec   min hrs       dte   mnth   year

 START:

 DO
  If pinb.2 = 1 then gosub always_on 'incase a person wants it always on during night	 
   gosub gettime
   gosub caltime
    pause 6000   
   gosub lighton_off
LOOP 
     
      
GETTIME: 'thanks to MARKS for the gettime code below 
    HI2Csetup I2Cmaster, %11010000, I2Cslow_32, I2Cbyte  ' Set  DS1307 to 100kbps 
      HI2Cin  $0 , (secs,mins,hours,day,date,month,year) ' Read DS1307
        FOR bptr = 1 TO 6   
          @bptr = @bptr/$10*250+@bptr                     ' Convert BCD to Decimal  
        NEXT       
     CommonYear = year //4 +3 /4            ' CommonYear =1              
      DayNumber = month +9 /12   
      DayNumber = CommonYear + DayNumber * DayNumber
      DayNumber = month *275 /9 +date -30 -DayNumber 
           DayS = year *512 **46752         ' year =1 to 99    
       DSTstart = Days +72//7                 
       DSTstart = 74 -CommonYear -DSTstart  ' Second SunDay in March                  
         DSTend = DSTstart +238              ' First SunDay in November 	   
	IF DayNumber < DSTstart OR DayNumber > DSTend THEN caltime
	IF DayNumber = DSTstart AND hours <2 THEN caltime   ' DST starts at 0200 
	IF DayNumber = DSTend   AND hours >1 THEN caltime   ' DST ends at 0200
	   IF hours =23 THEN : INC date  
	     IF month =4 or month =6 or month =9  and date =31 OR date=32 THEN : date =1 INC month: ENDIF
	   ENDIF : hours =hours +1//24 
RETURN	   
	   	   	           
CALTIME:
  If    month = 1 then 'january
    LOOKUP  hours,   (1,2,2,2,2,2,2,1,0,0,00,00,00,0,0,0,0,1,1,1,1,1,01,01), on_off_hour
    '     24 hours      12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11
 elseif month = 2 then 'february
    LOOKUP  hours,   (1,2,2,2,2,2,2,1,0,0,00,00,00,0,0,0,0,1,1,1,1,1,01,01), on_off_hour
    '     24 hours      12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11
 elseif month = 3 then 'march
    LOOKUP  hours,   (1,2,2,2,2,2,2,1,0,0,00,00,00,0,0,0,0,0,1,1,1,1,01,01), on_off_hour
    '     24 hours      12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11   
 elseif month = 4 then 'april
    LOOKUP  hours,   (1,2,2,2,2,2,1,0,0,0,00,00,00,0,0,0,0,0,0,1,1,1,01,01), on_off_hour
    '     24 hours      12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11    
 elseif month = 5 then 'may
    LOOKUP  hours,   (1,2,2,2,2,2,1,0,0,0,00,00,00,0,0,0,0,0,0,0,1,1,01,01), on_off_hour
    '     24 hours      12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11   
 elseif month = 6 then 'june
    LOOKUP  hours,   (1,2,2,2,2,1,0,0,0,0,00,00,00,0,0,0,0,0,0,0,1,1,01,01), on_off_hour
    '     24 hours      12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11   
 elseif month = 7 then 'july
    LOOKUP  hours,   (1,2,2,2,2,1,0,0,0,0,00,00,00,0,0,0,0,0,0,0,1,1,01,01), on_off_hour
    '     24 hours      12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11    
 elseif month = 8 then 'august
    LOOKUP  hours,   (1,2,2,2,2,2,1,0,0,0,00,00,00,0,0,0,0,0,0,1,1,1,01,01), on_off_hour
    '     24 hours      12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11   
 elseif month = 9 then 'september
    LOOKUP  hours,   (1,2,2,2,2,2,2,1,0,0,00,00,00,0,0,0,0,0,0,1,1,1,01,01), on_off_hour
    '     24 hours      12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11    
 elseif month = 10 then 'october
    LOOKUP  hours,   (1,2,2,2,2,2,2,1,0,0,00,00,00,0,0,0,0,0,1,1,1,1,01,01), on_off_hour
    '     24 hours      12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11 
 elseif month = 11 then 'november
    LOOKUP  hours,   (1,2,2,2,2,2,2,1,0,0,00,00,00,0,0,0,0,1,1,1,1,1,01,01), on_off_hour
    '  24 hours      12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11    
 elseif month = 12 then 'december
    LOOKUP  hours,   (1,2,2,2,2,2,2,1,0,0,00,00,00,0,0,0,1,1,1,1,1,1,01,01), on_off_hour
    '     24 hours      12,1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11    
 ENDIF

RETURN


LIGHTON_OFF:

If on_off_hour = 1 then 
	high b.0
elseif on_off_hour = 0 then
	low b.0
endif
If pinb.1 = 1 and on_off_hour = 2 then gosub lit_on_from_sensor 
RETURN	

LIT_ON_FROM_SENSOR:
High b.0
   wait 60
  for loopone = 0 to 100
	 pause 3000
 If pinb.1 = 1 then ; if sensor ativates 
	 Ltime =  200
   endif
       pause 3000
  next
  for loopone = 0 to Ltime
	 pause 6000
  next
 low b.0
RETURN
ALWAYS_ON:
DO
       gosub gettime
        gosub caltime
	  If on_off_hour = 0 then 
		  low b.0 
	elseif on_off_hour => 1 then
		high b.0
Endif
  pause 5000
LOOP until pinb.2 = 0
RETURN
of course it could be a lot shorter but in testing mode
your unprofessional friend
 

lbenson

Senior Member
Mark,

I hope you don't mind some suggestions, none of which functionally alter your program.

First, I would put "#picaxe 20M2" above "setfreq". This tells the editor (and also any reader) which picaxe you are using (I know your comments do that).

I would "uncomment" "InitialiseTime:" and the following "HI2Csetup" line, leaving only the "HI2Cout" line commented (except when you wish to reset the RTC values). Then remove the "HI2Csetup" line from GETTIME--you don't need to do the setup more than once.

In CALTIME, a comment would be good noting the significance of 0, 1, and 2 in your LOOKUP commands.

Finally, I would regularize your indentation of lines. I typically use 2 spaces for each level of indentation, but many choices will work. What they should be is standardized throughout. A new level of indentation is started within a block (between "IF" and "ENDIF", "FOR" and "NEXT", "DO" and "LOOP", etc).

While regularizing indentation will not alter the execution of your program, it will make it easier for others to read, and for you to read if you return to the program after some time has lapsed.
 
Last edited:

newplumber

Senior Member
Thanks Lance and I always like yours/others comments ...
When I copy and past it in this forum box it gets all unindentation confused (thats my excuse anyway :) )
Then remove the "HI2Csetup" line from GETTIME--you don't need to do the setup more than once.
Yes true thats why its good to have friends like you
In CALTIME, a comment would be good noting the significance of 0, 1, and 2 in your LOOKUP commands
I guess I'm still learning but maybe i should comment that it is in 24 hr mood and 0 hour = 12 am but if i am wrong which works
then its hard to comment lol
but thanks again
I have it on testing so it been awesome to see it work so far
Also I have it (outdoor light)starting on/off from top of hours but looking at the North Dakota sunrise/sunset time graph for each day
I am trying to figure out a simpler way to read minutes so it could be closer to the minute of sunrise/sunset each day
Mark
 

lbenson

Senior Member
Mark--Glad you have it running.
... "In CALTIME, a comment would be good noting the significance of 0, 1, and 2 in your LOOKUP commands" ...
I meant a comment describing the significance of the values 0, 1, 2 which are assigned to "on_off_hour" by the LOOKUP command (I know that by reading your program, one could see how "on_off_hour" is used, and a manager of mine maintained that "The best documentation is a working program", but sometimes a little assistance in the way of an informative comment can help.)

... When I copy and past it in this forum box it gets all unindentation confused (thats my excuse anyway ) ...
I thought that was probably the case. That suggests that you are using tabs for indentation. The problem with that is that when you copy the code into some other place (like Word or the forum) which has tab spacing different from what you are using in the Program Editor, everything gets shifted around, especially if you have a mix of spaces and tabs. This is why I always use spaces (2 for me) and never tabs.

Others, though, maintain that the use of tabs is best, because they can specify the tab spacing when they copy the code into the word processing program which they prefer. Horses for Courses. (But I think that spaces work most consistently.)
 

newplumber

Senior Member
Hi Lance okay thanks I understand now 0,1,2 in the lookup why a comment should to be there
I guess when I write code comments...its hard to see how others will/will not understand it but comments always help me in 1000 ways
i guess i am used to reading everyone else's in their code
as far as pasting code in this forum ..it seems that my computer pastes the code all against the left side tabs / spaces are deleted
so the next time i paste i should retab/respace the lines
Another thing about this forum is if I write this long of a message and click(post quick reply) it kicks me out so I have to re login
of course after I copy this message ...I learned awhile ago ...to always copy this/any of my messages before i click "post quick reply"
could be something on my side or picaxe side and timing out while trying to reply to thread...course i'm no puter guru

BTW I don't know if texasclodhopper is here and if he is ...that storm is sure messing with his Texas and hope he and all is okay
I wish I was closer to help in some small way which after the floods die down maybe we (our company) can
mark
 

techElder

Well-known member
BTW I don't know if texasclodhopper is here and if he is ...that storm is sure messing with his Texas and hope he and all is okay. I wish I was closer to help in some small way which after the floods die down maybe we (our company) can
mark
Thanks for thinking about us. Actually, we live just northeast of Houston and have experienced at least 40 inches of rain in the last 3 or 4 days. Will easily be over 50 inches of rain by Friday. I have a brother with Down Syndrome with a caregiver that lives in a 4th floor apartment where they are waiting for a rise in flood water up to 14 feet due to a dam upstream being opened to drain a lake level down. No power; no running water. A couple more days and a couple of months of cleanup to go.
 

lbenson

Senior Member
Tex--hope you, your brother, his caretaker, and hundreds of thousands of others stay safe. 50 inches of rain is unimaginable. Where I am, on the Mersey river in Nova Scotia, I suspect that amount would overflow and wash out the mostly earthen dam on Lake Rossignal, which would overwhelm the 4 power generating dams above me, and inundate all. I suppose we would get enough warning to be able to drive to higher ground a mile away (but from there there is no road connection to anywhere--this has me thinking that the best choice would be the longer route over the bridge and another mile along the river to get to the elevated highway). Best of luck.

... as far as pasting code in this forum ..it seems that my computer pastes the code all against the left side tabs / spaces are deleted ...
Mark--if you paste without the [ code] tags, all white space (spaces and tabs together) is compressed to a single space. Within [ code] tags, tabs are expanded in a way that is likely to be different from the way they are expanded in either of the Program Editors. That's why I like to use just spaces for indentation.
 

techElder

Well-known member
Water levels are still rising in the area as this storm moves away from land. What we're seeing is water levels only referenced in the 500 year flood plan.

Mark, I have to mention that the PE has a code copy feature that takes care of all that formatting. All you have to do is paste into a post here on the forum.
 

newplumber

Senior Member
@ Texasclodhopper thanks I will look into that (PE copy paste feature) ... I also had a Down Syndrome brother (year younger then me) ...he was a blessing always smiling ... he died 14 years ago in a ski accident
so back to the harvey disaster... I searched every where up here (ND) for 6" diesel pumps and all are heading your way so thats good but seems they would be like using a mcdonalds straw to drain a large pond
but at least millions are trying to help

@Lbenson thanks I will keep experiencing.
Mark
 

marks

Senior Member
Hi newplumber,
I haven't wrote any code in a long while but it is interesting to look here now and again, it does seem quiet lol.
it was interesting to plot the sunrise/ sunset for your area i was surprised how different it is compared to Perth.
(it makes you understand why we dont have or need DST here)
I've only briefly simulated , it should show the sunset sunrise times for each day within a few minutes.
I'm unsure if its possible to upload an excell sheet if it is I could add 1 to my ds3232 code snippets later
,if you pm me your lat and long
i could proberly upload table data for your location if you wish.
I used details for Fargo as its easy to check some times with go0gle .
good luck with your project!

Code:
	SYMBOL date          = B5 
      SYMBOL month         = B6
      SYMBOL year          = B7
      SYMBOL CommonYear    = b8
	SYMBOL DayLight      = b9
	SYMBOL D0            = b10
      SYMBOL D1            = b11
      SYMBOL D2            = b12
      SYMBOL D3            = b13
      SYMBOL D4            = b14
      SYMBOL D5            = b15
     
      SYMBOL DayNumber     = W10 
	SYMBOL SunRise       = W11
      SYMBOL SunSet        = W12
	
	Table   0,(253,252,250,246,240,234,226,217,207,197) ' Fargo, North Dakota Sunrise data +240mins   
	Table  10,(186,175,163,151,139,127,116,104, 93 ,82) ' Latitude   46.8772 (N)
	Table  20,( 73, 63, 55, 48, 42, 37, 34, 32, 32, 33) ' Longitude -96.7898 (W)
	Table  30,( 36, 40, 45, 50, 57, 64, 71, 79, 87, 95) ' TimeZone  -6  (GMT)
	Table  40,(102,110,118,126,133,141,149,157,166,174) ' data plot interval every sixth day of year
	Table  50,(183,192,201,209,218,226,233,240,245,249) ' about every 12 miles from location can affect data by 1 minute
	Table  60,(252,253)                                      
	Table 100,( 19, 25, 32, 40, 48, 57, 67, 76, 85, 94) ' SunSet data +990mins
	Table 110,(103,112,120,128,137,145,153,162,170,178)
	Table 120,(186,194,202,209,216,222,227,231,234,236)
	Table 130,(236,234,231,226,220,213,205,196,186,175)
	Table 140,(164,153,141,129,117,105, 93, 81, 70, 59)
	Table 150,( 49, 40, 31, 24, 18, 13, 10,  9,  9, 11)
	Table 160,( 14, 19)
	
Initialize:            
   HI2Csetup I2Cmaster, %11010000, I2Cslow, I2Cbyte       ' Set to 100kbps 
       HI2Cout $0 , ( $00, $59, $23 , 0 , $30, $08 , $17) ' Uncomment to Program         example (11.59.00 PM)
;Progam  Registers  (secs,mins,hours,day,date,month,year) ' Enter in BCD           hours example ( $0 to $23 )
      
 Main:      
     HI2Csetup I2Cmaster, %11010000, I2Cslow, I2Cbyte        
      HI2Cin $4,   (date,month,year) ' read date DS3231 or DS1307
      
      FOR bptr = 5 TO 7   
        @bptr = @bptr/16*250+@bptr   ' convert BCD to Binary  
     NEXT
     
    DayNumberOfTheYear:                 
     CommonYear = year //4 +3 /4     'CommonYear =1 so leapYear =0 
      DayNumber = month +9 /12   
      DayNumber = CommonYear + DayNumber * DayNumber
      DayNumber = month *275 /9 +date -30 -DayNumber
     
     SunriseToSunset:
     Daylight = Daynumber /6 : READtable Daylight,D0 : INC Daylight :  READtable Daylight,D1
     DayLight = DayLight +99 : READtable Daylight,D2 : INC Daylight :  READtable Daylight,D3
     
     DayLight = DayNumber //6 : IF D0 > D1 THEN : SWAP D0,D1 : DayLight = 6 -DayLight : ENDIF
      SunRise = D1 -D0 * Daylight /6 +D0 +240
     DayLight = DayNumber //6 : IF D2 > D3 THEN : SWAP D2,D3 : DayLight = 6 -DayLight : ENDIF
       SunSet = D3 -D2 * Daylight /6 +D2 +990
	 
	d0=sunrise/60
	d1=sunrise//60 /10
	d4=sunrise//60//10
	d2=sunset/60
	d3=sunset//60 /10
	d5=sunset//60//10
	
	Sertxd ("  Day ",#DayNumber,"  Year 20",#year,"    Sunrise ",#d0,":",#d1,#d4,"    Sunset ",#d2,":",#d3,#d5,CR,LF) 	
     
     END
      GOTO Main
 

lbenson

Senior Member
marks--sweet. You can upload an excel spreadsheet (if small enough to fit the forum limits) by renaming it with a, for instance, ".bas" file extension. Downloaders then must rename it ".xls" (or whatever).

Is your excel code such that one can enter a longitude and latitude and have it generate the sunset/sunrise Table data?
 

marks

Senior Member
Hi Ibenson,
yer it will allow any one to generate there own data
specific to there location but will have to manualy enter it lol .
you will just have to change the latitude ,longitude and timezzone info
it will be about 420kb tho.
 

marks

Senior Member
Sorry Ibenson,
there appears to be a 195kb limit

perhaps send a message and I'll email back to you.
 
Last edited:

johnlong

Senior Member
Hi Newplumber
Just having a look at your board in post 9
Can you if you have the time explain the 33K ressistor across the +/- of the SSR
regards
john
 

newplumber

Senior Member
WOW thanks a lot MARKS ...I am very impressed and thankful for your code + time although I do not have time right now to try it out but its awesome to have people like you around
and of course all you other pros .. and keep it somewhat simple for us new/old/semi educated people
I will later on try it out and report back my mistakes (hopefully down to just 500 or less this time)

@johnlong " 33k resistor" lol shoot I wish i had a answer or...a smart answer
but my unimaginable thinking is if the wires some how create noise from the 120v ac lines being close then it should stop false trigger
but i believe when the picaxe pin is a 0 it would ground out the little noise anyway so maybe it doesn't need the resistor
in short I always trying to add pull down resistors ... just so my ssr or anything don't turn on unexpectedly

@friends ... my SSR's are known to have power (ac voltage) slip by when the SSR is in off mode with a few volts
which can light up or flicker the led bulbs ... has anyone came up with a solution to stop this
I heard of people using a 2 or less watt bulb in parallel to stop the flickering but was just wondering if there was a better idea
I will draw a schematic when I get time to make more/less sense
thanks Mark
 

premelec

Senior Member
@newplumber - in various situations of feedthru flicker I've added R across load - e.g. 47000 ohms - empirical...
 

newplumber

Senior Member
@ premelec thanks to make it clear I drew a simple plan
so a 1/2 watt resistor should work if I have my
calculations right with 120 volts makes .30 watts but it may be for DC

@marks it is so cool of your code in post #20 works like a charm
only problem i am having is combining your daylight saving code to the sunset code
and with a 20m2 I am running out of bytes but it seems you figured it all in ... will keep playing around with it
thanks again
 

Attachments

premelec

Senior Member
Power = v*v/R - 120 x 120 / 47000 = .306 watts so 1/2 w ok if in free air... note spikes on line may make some feed thru blips...
 

lbenson

Senior Member
... with a 20m2 I am running out of bytes ...
Mark--you're aware that a second "slot" is available for code?

Also 512 bytes (minus the 28 lowest used for the named variables) of "upper" RAM available with PEEK, POKE, and @BPTR?

May require some trickery to get it organized.
 
Last edited:

AllyCat

Senior Member
Hi,

only problem i am having is combining your daylight saving code to the sunset code
and with a 20m2 I am running out of bytes
Yes, it depends which type of bytes you're running out of: RAM (variables), EEPROM/Table or Program memory, but there are plenty of "tricks" to "find" more of any type.

It's almost certainly best to run the RTC and almost the entire program with "non DST" times (or perhaps entirely in DST, as that's the longer period). Neither the Sun nor the Earth's rotation know anything about DST!

The only area where you might need to consider DST is if you want the Light to change it's behaviour at a specific time of day such as 24:00 hours (I know you normally use am/pm, but I find 12:00 am/pm very confusing, and it's not "midnight" during DST). For that case, just add/subtract a one hour offset during the dates of DST.

Cheers, Alan..
 

PhilHornby

Senior Member
SSR?

@friends ... my SSR's are known to have power (ac voltage) slip by when the SSR is in off mode with a few volts
which can light up or flicker the led bulbs ... has anyone came up with a solution to stop this
I don't know if you followed the saga of my SSR? : http://www.picaxeforum.co.uk/showthread.php?30157-Audible-noise-from-an-SSR! ...

I'd always imagined an SSR to be a rather magical device, containing all manner of exotic hardware to produce a 100% equivalent of a mechanical relay ... behaving in exactly the same way as one, with all loads.

Having opened the box, I found: a TRIAC, an opto-coupler and a snubber circuit ... implemented using components of variable quality (with no data sheets for any of them - including the heatsink). Of course, if you spend enough money, you stand a much better chance of getting a decent one; but it still seems a bit of a pig-in-a-poke in my book!

(I bet if you try Crydom's Total Cost of Ownership calculator, you can't justify an expensive one, for this project...)

How about one of these?
:p
 

newplumber

Senior Member
what exactly is it that the 47K 1/2 watt resistor is doing?
@Lbenson ...I don't know :) premelec says he does it and he is cool so I wanna be cool so I am going to do it tooJK
but for real I have to stop the drain thru voltage of the ssr so i am going to test it and see if it works
and yes I know there is a second slot for memory but like you said "trickery" is the best word for me using it

@ allycat ...thanks , I am some what following you, but since I'm using Marks code I now know the sunrise/sunset times of each day
now to turn light on/off I need to match the sunrise/sunset with the hour/minute from the RTC
lol its a piece of cake for you pros ... but for me I have to program a program to program program (in other words called wreckless programming)
so I have a start or idea rather ...which is to get the sunrise/set times using the date i.e. 8-31-17
then use HI2Cin to read the time ... then make some out of this world code to match it with sunrise/set
with when the light shuts off or on and like you said 12 is confusing so I would stay with 24
and I also need to do more homework on eeprom bytes ...variable ones b0-b27 is easiest and seem to get used up the fastest
but thanks again

@PhilHornby thanks but since this light is going/should be "STATE OF THE ART" (i hope) then I must use SSR's
and that and I told all my local friend ( yes just one) that since this light is built by the help of picaxe forum pros
I will have one of the smartest out door lights in .....50 miles!
In short I think it will save power using a SSR instead of holding a relay closed when on.
 

techElder

Well-known member
A real "STATE OF THE ART" light would bring the brightness of the light up slowly. A relay is just ON/OFF, but with your "STATE OF THE ART" electronic solution why mimic a relay? :D
 

newplumber

Senior Member
@texasclodhopper yes true that would be neat ...a smart dim-able light and why mimic a relay? lol
well sadly that's all i know ...relay or hand flips switch

@PhilHornby :) true ... but it gets cold up here in the winter time maybe in the summer I can
use some type of air conditioning resistor
 

premelec

Senior Member
@lbenson - FWIW he said there was some flicker feed through [post#26] - LEDs can show with _very_ low power. I have found in some situations like this a 47K R on load will kill the flicker... it assumes the SSR is NOT turning on but there is some capacitive feed through or such... Sometimes the R works... sometimes not ;-0
 
Last edited:

lbenson

Senior Member
... (in other words called wreckless programming) ...
"wreckless programming" (i.e., no crashes) sounds better than "reckless programming" (no caution), but I tend towards the reckless variety (unless working with 120V), since at 5V, pretty much anything I break programmatically can be fixed programmatically [JK].

Thanks for the clarification, premelec. I hate it when OFF isn't OFF.
 
Top