Search This Blog

Thursday, August 20, 2015

PIR and Relay for an automatic light switch

Here is a project I made to turn on my basement light when someone enters the laundry room. I chose the PICAXE 08M2 for this because it was just the right little chip for the job. When I first started this project I thought it would be a straight forward "easy" thing to do, well, it was not!  There were little issues like the relay closing between sessions and annoying little timeing problems in my first attempt. I ended up throwing out the that plan and decided to give the FlowCharting method a try. After a few attempts I finnaly came up with this diagram.

I used two tasks here. One that just checks the Passive Infra-Red sensor over and over. And one task that acts like a control center. That is, when the first loop is triggered , it decides if it should turn on the light based on some criteria. One tricky thing I ad to overcome was if the system had already been triggered and a person as still in the room should the timer be reset or simply run out and then re-evaluate the situation. Designing something like this is not as easy as it looks at first. There are many considerations to take in to account. This flowchart seems to work OK so I decided to turn it into code. Here it is....
'
-----------------------------------------------------------------------------------------
symbol varA = b0
symbol varB = b1
symbol varC = b2
symbol varD = b3
symbol varE = b4
symbol varF = b5
symbol varG = b6
symbol varH = b7
symbol varI = b8
symbol varJ = b9
symbol varK = b10
symbol varL = b11
symbol varM = b12
symbol varN = b13
symbol varO = b14
symbol varP = b15
symbol varQ = b16
symbol varR = b17
symbol varS = b18
symbol varT = b19
symbol varU = b20
symbol varV = b21
symbol varTEMPBYTE1 = b22
symbol varTEMPBYTE2 = b23
symbol varTEMPBYTE3 = b24
symbol varTEMPBYTE4 = b25
symbol varTEMPBYTE5 = b26
symbol varTEMPBYTE6 = b27
symbol varTEMPWORD1 = w11
symbol varTEMPWORD2 = w12
symbol varTEMPWORD3 = w13
}


main:
Cell_7_2:
let dirsC = 23

Cell_7_3:
pause 1000 'Sanity delay, give time to initialize the PIR
Cell_7_5: ' Start searching for movement
if pinC.3=1 then

goto Cell_7_7
end if
Cell_7_9: ' No movement = LED off (RED), keep searching
low C.1
high C.2
goto Cell_7_5

Cell_7_7: ' Movement = LED ON (GRN), keep searching.
high C.1
low C.2
goto Cell_7_5

Cell_4_1:
start1:

Cell_4_2:  'Set the run timer for 60 secs in varD
let varD = 60    
Cell_4_4: ' Watch for movement, if true then...
if pinC.3=1 then

goto Cell_4_5
end if
goto Cell_4_4

Cell_4_5: ' ...Set the RUN timer to 0 secs.
let time = 0 '    
Cell_4_6: ' Start the RUN timer
enabletime
Cell_4_8: 'Run the sub that turns on relay and the then come back.
gosub prc_LightsON
Cell_4_10: ' Check the RUN timer, if NOT expired, keep checking until true.
if time >= varD then
goto Cell_4_11
end if
goto Cell_4_10

Cell_4_11: 'RESET the RUN timer to 0
let time = 0    
Cell_4_12: ' Check once more for movement, if not, shut off lights, keep looking.
if pinC.3=1 then

goto Cell_4_5
end if
Cell_7_12:
gosub prc_LightsOFF
goto Cell_4_4

Cell_1_9: ' ********* PROCEDURES ****************************************
prc_LightsOFF:
Cell_1_11: ' LIGHTS OFF
low C.4
Cell_1_12:
return
Cell_1_4: '  LIGHTS ON
prc_LightsON:
Cell_1_6:
high C.4
Cell_1_7:
return

#no_data 'reduce download time
-------------------------------------------------------------------------------------------------

Now that I had the code done, I needed to build a schematic for the circuit. I used a FREE program from DesignSpark.com The software can make schematics and PCB boards.


...And from the schematic I made this prototype to test it out. This was a pretty simple curcuit to make. It uses one input for the PIR sensor and three outputs. Two for the Bi-color LED and one for the Relay.

Everything went pretty smooth in testing so next thing was design a PCB for it.


I have not made this board yet. There are some errors on the board that I am trying to fix, but may not be able to. This is all a learning experience for me. I LOVE IT!  It can be painful, but its fun. 

JSK

Wednesday, June 17, 2015

LEDWAND and Light Painting

I have been working hard on a new project. It is a tool used for "Light Painting". 
  1. Light painting, or light drawing, is a photographic technique in which exposures are made by moving a hand-held light source while taking a long exposure photograph, either to illuminate a subject or to shine a point of light directly at the camera.

  2. I call it the LEDWAND. There will be more on the making and use of this tool on the Arduino page, but in the meantime here are some pics made with it. 
  3. There are several modes including this one.


  4. Removable filters allow all different kinds of accents like the to parallel lines shown here in the curve.

  5. Lots of sweeping colors here.

  6. I love taking these pictures. It is a blast!
  7. I am making a tutorial on how to this kind of photography to be posted here soon.
  8. :)