Reading Passive Infrared Motion Sensor

I’m trying to read a PIR Sensor (#555-28027) from parallax with the following code and all it does is return zero. I have it hooked up to pin 4 on the BBII. Does this code look correct?

[code]pingRaw var word
ping CON P4

main:
gosub getping
goto main

getping:
pulsin ping, 0, pingRaw 'read the pir
PAUSE 100
gosub debuggery
return

debuggery:
serout S_OUT, i9600, "pingRaw: ",dec pingRaw, 13]
return
[/code]

Manual
parallax.com/Portals/0/Downl … r-v1.4.pdf

I would recommend you load the code provided in the PDF you linked, rather than using code for a PING!

I did and it worked! :smiley:

I would have expected Pulsin to have come back with a large value or zero. I thought that it was reading the duration of the signal on the pin. If the pin was set to high I thought it would timeout at 65535 and give me large pulse value.
Pulsin
“Measures the duration of an input pulse on a specified pin.”
Then I went on to read “If no pulse is detected within the timeout value duration will be set to 0.” Even though it was set to high it must not have considered that a “pulse” (albeit a big pulse) and set it to zero.

At anyrate I did some reading on the basic stamp and then some reading in the basicAtomPro manual and found an equivalent to what they were doing
"IN and OUT Pin variables:"
IN# or OUT# 1 P#
(where # is a number from 0 – 31)
The state bit is 0 for low and 1 for high.

hldpin1       var word
counter       var word
prev_hldpin1    var word
FOR counter = 40 TO 0                   ' Wait 40 Seconds For PIR Warm-Up
  PAUSE 1000                            ' Display Counter Every Second
NEXT

Main:

hldpin1 = IN4 ' Display Status Of P4.  
if hldpin1 <> prev_hldpin1 then 'only send if value has changed
   serout S_OUT, i9600, [dec hldpin1, 13] 'output to com port
   prev_hldpin1 = hldpin1
endif
   
PAUSE 100 ' Small Delay
if hldpin1 = 1 then
   gosub pirnoise
endif
goto main ' Repeat Forever

pirnoise:
sound P9,[10\1046.502]
low P9
return

The PIR sensors just has a level out then. The Ping and SRF08 sensors require more interaction.

Alan KM6VV