;*******************PIR PASSIVE INFRARED MOTION SENSOR SMART NIGHT LIGHT**************************** ;Use a LDR light sensor to turn on a pir motion sensor as it gets darker. ;Change to have a START_UP_ROUTINE ;Change the LIGHT_THRESHOLD value to turn device LED on when getting dark ;Change the length of TIME the LED turns on ;Advanced ;Change TWO MODES at power up. Could have two light_threshold levels #Picaxe08M2 ;Tells picaxe its a 08M2 chip ;#No_Data ; shortens the upload process symbol Light_threshold = b1 ;Create SYMBOL LIGHT_THRESHOLD and give it variable = b1 Light_threshold = 100 ;Set the CONSTANT LIGHT_THRESHOLD below which the night light will trigger . symbol Light_Level = b2 ;Create SYMBOL LIGHT_LEVEL and give it variable = b2 symbol Motion = b3 ;Create SYMBOL MOTION and give it variable = b3 let b3 = pin3 ;make PIN3 = b3 ;********MAIN LOOP************** Main: b3 = 0 ; reset b3 to 0 b3 = pin3 ; make PIN3 = b3 gosub check_light_level ; goto subroutine CHECK_LIGHT_LEVEL if light_level < light_threshold then ; CONDTIONAL Statement, compare light_level to light_threshold gosub check_motion ; If light_level is less than light_threshold go subroutine check_motion endif ; end of if statement nap 4 ; take a low power sleep goto main ;*******END OF MAIN LOOP*************** Check_Light_Level: readadc 1, light_level ;Read the analogue VOLTAGE on PIN1 and PUT INTO VARIABLE "LIGHT_LEVEL" pause 10 debug return ;************************************************************************ Check_Motion: if pin3 = 1 then ;Check the PIR motion sensor on pin3, High/1 means motion sensor triggered pause 20 debug gosub night_light ; If motion sensor triggered, then go to subroutine night_light endif return ;return to Main Loop and check light level ;************************************************************************* Night_Light: debug high 4 ;Turn On pin4 wait 5 ;LED stays on for 5 seconds low 4 ;Turn off pin4 goto main return ;**************************END OF CODE *************************************