Sunteți pe pagina 1din 3

Automatic security lights with PICAXE -08 and PIR Sensor

Combination PIR sensor and floodlight units are cheap but rather inflexible if you want to locate the sensor and light in different places. In my case, I wanted to detect movement on the driveway and switch on the lights in the carport around the corner. Yet another job for the ubiquitous PICAXE-08 microcontroller!

A standard PIR sensor is used as the movement detector. The sensor interfaces to the PICAXE (IC1) on input 2 (pin 5). This pin is pulled low via isolation diode D3 and the normally open (NO) output of the sensor whenever movement is detected. It can also be pulled low by transistor Q1, which acts as a simple inverter for sensors with normally closed (NC) outputs. So that the lights arent needlessly switched on during the day, a light-dependent resistor (LDR) is used as an ambient light sensor. Together with a 100k resistor, the LDR forms a simple voltage divider, which converts its changing resistance to a changing voltage at the micros analog input (pin 6). As light falling on the sensor decreases, its resistance increases, resulting in less voltage at the analog input. Below a preprogrammed threshold voltage, it is assumed to be night-time.

When movement is detected, a program timer is started and the relay is energised via Q2, switching on the lights. If no further movement is detected, the lights will turn off after about 10 minutes. However, if movement is detected within this period, the timer is reset, extending the on period a further 10 minutes. The on time is easily modified to suit your installation (see program listing). As shown, power comes from a small 9VAC transformer, bridge rectifier (BR1) and a 2200F filter capacitor. A 9V DC plugpack could also be used; just omit the transformer and BR1 and substitute a 100F 25V capacitor for the 2200F unit. A polarity protection diode (eg, 1N4004) in series with the positive plugpack input is also a good idea. A 7805 low-power regulator provides a stable +5V supply for the PICAXE and associated circuitry. Note that a diode (D2) is included in series with the regulator output to reduce the supply voltage to about 4.4V, which improved system reliability in hot weather. All 240VAC wiring should be properly terminated and insulated, and the project housed in a suitable plastic instrument case that is protected from the elements. Modifications to fixed mains wiring will require the services of a licensed electrician. Jeff Monegal, North Maclean, Qld. ($50)
' Security Lights Controller ' Jeff Monegal 18 May 2004 ' PICAXE-08 symbol timer = w6 'used as a lights on timer

'-----------------------------------------------------------------------------------' The value in the B0 register from the readadc command below may need to be ' changed to suit different types of LDR. Use the debug command to monitor ' the value given by your particular LDR. Dont forget to change the rest of ' the readadc values throughout the program. '------------------------------------------------------------------------------------start: readadc 1,b0 debug b0 if b0 < 140 then night_time goto start night_time: if input2 = 0 then detect readadc 1,b0 if b0 > 140 then maybe_daytime goto night_time 'read the LDR 'look at the value given by your LDR 'if less than 140 then it is night time

detect: pause 100 if input2 = 0 then yes_detect goto night_time yes_detect: timer = 0 high 4 time_loop: readadc 1,b0 if b0 > 140 then maybe_daytime timer = timer + 1 if timer > 3000 then time_out installation pause 100 if input2 = 1 then time_loop pause 100 movement if input2 = 1 then time_loop timer = 0 goto time_loop time_out: low 4 pause 3000 again goto night_time maybe_daytime: pause 2000 readadc 1,b0 if b0 > 140 then is_daytime goto night_time is_daytime: low 4 goto start

'short delay then look at the PIR again to confirm 'a movement detection and not just noise

'clear timer counter 'turn on the lights

'add one to the time counter 'change to suit your '(3000 x 200mS = 600s) 'short delay then look again for 'reset timer if movement detected

'turn the lights off '3s before lights can be triggered

'turn lights off in case they are on

S-ar putea să vă placă și