Datasheet
Copyright © Parallax Inc. PIR Sensor (#555-28027) v2.2 6/13/2012 Page 4 of 5
BASIC Stamp
®
Example Code
This program will display the current state of the output pin from the PIR Sensor connected to P0 using
the Debug Terminal. The Debug Terminal is built into the BASIC Stamp Editor software. The software is a
free download from www.parallax.com/basicstampsoftware.
' PIR_Simple.bs2
' Displays the current state of the PIR Sensor connected to P0
' {$STAMP BS2}
' {$PBASIC 2.5}
PAUSE 40000 ' PIR warm-up time
DO
DEBUG HOME, BIN1 IN0 ' Display state of P0
PAUSE 100 ' Small Delay
LOOP ' Repeat Forever
Propeller
™
P8X32A Example Code
Note: This application uses the Parallax Serial Terminal to display the device output. The object and the
Parallax Serial Terminal itself are included with the Propeller Tool v1.2.7 or higher, which is available from
the Downloads link at www.parallax.com/Propeller.
'' PIR_Simple.spin
'' Displays the current state of the PIR Sensor connected to P0
CON
_clkmode = xtal1 + pll16x ' Setting Clock Mode to Crystal 1 with 16 multiplier
_xinfreq = 5_000_000 ' Propeller set to run at 80MHz
VAR
byte state ' Declare variable state to store PIR output
OBJ
pst : "Parallax Serial Terminal"
PUB PIR ' Public Method name PIR
dira[0]~ ' Set pin 0 to input
pst.start(115200) ' Start Parallax Serial Terminal at 115200 baud
waitcnt(clkfreq * 40 + cnt) ' PIR "warm-up" time
pst.clear ' Clear the screen
repeat
state := ina[0] ' Save state of PIR Sensor
pst.home ' Move cursor to position(0,0)
pst.str(string("IN0 = "))
pst.bin(state, 1) ' Display state
waitcnt(clkfreq/200 + cnt) ' Small delay