November 21, 2024, 08:37:42 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Using a PIR Sensor

Started by JonnyMac, February 13, 2007, 10:11:25 AM

Previous topic - Next topic

JonnyMac

Some PIR sensors can have a bit of "ragged" output which, under some circumstances, can lead to false triggering.  A simple way to prevent false triggering of your prop is to wait until the PIR signal is present for at least 1/4 second -- very short in human terms, but a very long time in microcontroller terms.  A neat little math trick, called "combinatorial logic" lets us update or clear the PIR timer variable with one line of code.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

PIR             PIN     14                      ' SETUP = DN


' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1
IsOff           CON     0


' -----[ Variables ]-------------------------------------------------------

pirTimer        VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:


' -----[ Program Code ]----------------------------------------------------

Main:
  DO
    pirTimer = (pirTimer + PIR) * PIR
    PAUSE 10
  LOOP UNTIL (pirTimer > 25)

  ' control code here

  END


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -----[ EEPROM Data ]-----------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

JCrank

I'm having problems getting the PIR to work.  I have the code below PIN 1 is connected to an LED.

The sensor is not seeing motion, I have it covered up, but the LED just keeps going on and off it should be staying off.

Also I used debug to monitor pin 14 and it just seems to be randomly turning on and off.


' -----[ I/O Definitions ]-------------------------------------------------

PIR             PIN     14                      ' SETUP = DN


' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1
IsOff           CON     0


' -----[ Variables ]-------------------------------------------------------

pirTimer        VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:
  PAUSE 10000
  pirTimer = 0
  LOW 1


' -----[ Program Code ]----------------------------------------------------

Main:
  DO
    pirTimer = (pirTimer + PIR) * PIR
    PAUSE 10
  LOOP UNTIL (pirTimer > 25)

  HIGH 1

  GOTO Reset

JonnyMac

The reason is that you're making pin 1 an output (with LOW), and that pin needs to be an input.  Use the demo program above, and simply change the PIN declaration from 14 to 1.
Jon McPhalen
EFX-TEK Hollywood Office

JCrank

The PIR is connected to pin 14  pin 1 is connected to an LED so I can see when the PIR senses motion.

What I'm saying is that When the PIR connected to pin 14 senses motion the led on pin 1 comes on then after a delay the LED goes off until the PIR senses motion again.

JonnyMac

Sorry, today has been a whirlwind: a phone interview, a visit to a local FX house (they guys who did the props for the movie, 300), lots of code... zoiks, I need to slow down. 

The way your code works a valid signal on the PIR should cause the LED to light for 10 second (dues to the PAUSE in the Reset section).  If it's not, send it back for an exchange.
Jon McPhalen
EFX-TEK Hollywood Office

JCrank

Thats no problem,

Just want to make sure I have it connected correctly.  The OUT pin on the PIR goes to W on the Prop-2 with setup on DN.  I tried the setup on DN and OFF with no noticeable difference.  I also tried moving the jumper on the PIR with no noticeable effect.

I now have it setup so the PIR will light an LED (no timing or anything).  With no movement in the room even with the PIR totally covered up the LED blinks randomly.

So maybe a bad PIR?

JonnyMac

Could be.  Send it back for an exchange.  We're now testing sensors before we send them since Parallax's supplier seems to have skipped that step.
Jon McPhalen
EFX-TEK Hollywood Office