Wednesday, April 9, 2008

code for motion sensor

' ========================================================================='' File...... PIR_Advanced_Demo.bs2' Purpose... Demonstrate PIR Sensor With Warm-Up Code' Author.... Parallax, Inc.' E-mail.... support@parallax.com' Started... 12-14-2005'' {$STAMP BS2}' {$PBASIC 2.5}'' =========================================================================
' -----[ Program Description ]---------------------------------------------
' This PIR demo allows you to see how to go about allowing a warm-up time' for the sensor to settle, as well as displayed number of times tripped' and possibly activating an alarm or relay, in this case the LED. The LED' should have a 220 ohm or 330 ohm resistor in series with it.
' -----[ I/O Definitions ]-------------------------------------------------
PIR PIN 15 ' I/O Pin For PIR SensorLED PIN 2 ' I/O Pin For LED
' -----[ Variables ]-------------------------------------------------------
counter VAR Byte ' Trip Counter
' -----[ Initialization ]--------------------------------------------------
DEBUG CLS ' Clear DEBUG ScreenFOR counter = 40 TO 0 ' Wait 40 Seconds For PIR Warm-Up DEBUG HOME, "WARMING UP:", DEC2 counter PAUSE 1000 ' Display Counter Every SecondNEXT
counter = 0 ' Clear Counter Variable
DEBUG HOME, "WAITING... " ' Display Waiting Message
' -----[ Program Code ]----------------------------------------------------
Main: DO IF PIR = 1 THEN ' Motion Detected? counter = counter + 1 ' Update Trip Counter HIGH LED ' Light LED DEBUG HOME, "TRIPPED...", DEC3 counter DO : LOOP UNTIL PIR = 0 ' Wait For PIR To Clear DEBUG HOME, "CLEARED...", DEC3 counter LOW LED ' Turn Off LED ENDIF LOOP

Labels:


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?