November 22, 2024, 08:45:01 AM

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.


PIR Sensor questions

Started by steveo, August 20, 2007, 07:05:52 AM

Previous topic - Next topic

steveo

Jon,
I'm having some issues getting my PIR sensor to work properly. The issue is the sensor seems to trigger randomly, and pretty much constantly. I've tried using your debounce code, and still got erratic results.

To get an idea of what might be happening I tried something like this (using the trainer):


Symbol PIR = PIN6

Main:

DEBUG PIR

GOTO Main

I then took the PIR and closed it up in a box, basically trying to get a consistent "0" output, but still a string of zeros and ones, marched down.

So what am I doing wrong?



JonnyMac

It's possible that you have a bad sensor.  Do you another you can try the same test with?  And you should ALWAYS debounce, even when testing.  Try this:

Main:
  DEBUG "Waiting... "
  pirCount = 0
  FOR idx = 1 TO 10
    pirCount = pirCount + 1 * PIR
    PAUSE 10
  NEXT
  IF pirCount < 10 THEN Main

  DEBUG "PIR Detected", CR
  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office

steveo

Jon,
No dice. I have the sensor in active HIGH position and i'm running the code you provided, but this sensor just seems to be constantly detecting movement regardless of how much time i give it to settle down.

I'm going to order another to be 100% sure it's not me.

JonnyMac

PIRs are twitchy beasts, but you should be able to get it to settle down.
Jon McPhalen
EFX-TEK Hollywood Office

steveo

This one here, she's no good. I was able to get it to settle by covering the lens completely in electrical tape. Unfortunately, any hole in the coverage at all just threw it right back to "always on" mode.

I need to get an AP8, so I'll throw another one on my next order and be done with this bad apple.

:)

steveo

So here's something a bit odd, I pulled off the lens (desperation move) and lo and behold - it behaves just fine. Picks up signal, calms down after about 13 seconds and she's good to go again. Working quite nice actually. Perhaps not so oddly enough I tried to mount it into a short length of PVC to restrict it's FOV, and it flipped out again, constantly reading high.


bpenman

I am having a similar problem with my PIR. What can I do if it constantly sees movement, and repeatedly triggers my Prop-1 while my other PIR in the same configuration on the same Prop-1 works as it should?

JonnyMac

Send it back for a replacement.  We have contacted Parallax with our concerns.
Jon McPhalen
EFX-TEK Hollywood Office

tj

hey jon,

mine is doing the same, it's maybe 2 weeks old. it doesn't seem to do it as often as stevos but, i can be far away and watch an the prop trips sporaticly. i can reset the board and get it to act right sometimes. should i send mine back also?

JonnyMac

If you're absolutely sure that it's the sensor and not something in the environment (EMI source, heavy IR source, etc.) then send it back and we'll replace it.  We've raised the issue with our friends at Parallax and I'm sure they'll do what they have to do on their end.  In the meantime, we're testing sensors before we send them out.
Jon McPhalen
EFX-TEK Hollywood Office

tj

i changed my code from, If pirtimer < 250  to If pirtimer < 300 and it seems to of stopped it, best i can tell anyways.

JonnyMac

If pirTimer is a byte then your code will never work because a byte can only hold a value up to 255.  Here's another way to extend PIR timing by using a byte -- it's a little less obvious than what I traditionally use, but it does save variable space over using a word for PIR timing.

Main:
  PAUSE 10
  pirTimer = pirTimer + 1 * PIR                 ' update or clear counter
  IF pirTimer < 30 THEN Main                    ' 30 x 10 ms = 300 ms


You determine the length of a valid signal, divide by 10 (the PAUSE value), then use that as the test.

Jon McPhalen
EFX-TEK Hollywood Office

tj

right, and assume it works because, the variable used was timer= w4 instead of b2 like you normally use. is this correct?

heres the code you wrote, with some additions for my use.


' =========================================================================
'
'   File...... PIR_Cycle_Leds.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2007 EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Led3            = PIN2
SYMBOL  Led2            = PIN1
SYMBOL  Led1            = PIN0
SYMBOL  Light           = PIN5
SYMBOL  Cyl             = PIN3
SYMBOL  Fog             = PIN4
' -----[ Constants ]-------------------------------------------------------

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0
SYMBOL  IsUp            = 1
SYMBOL  isDn            = 0

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

SYMBOL  ledTimer        = B2                    ' for LED flashing
SYMBOL  ledPntr         = B3
SYMBOL  timer           = W4
SYMBOL  lottery         = W5                    ' random value


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

Reset:
  PINS = %00000000                              ' clear outputs
  DIRS = %00111111                              ' set output pins (P0..P2)

  PAUSE 20000                                   ' warm-up/inter-show delay

  PINS = %00000001                              ' start with Led1 on
  ledTimer = 0
  timer = 0                                     ' clear for PIR debounce


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

Main:
  RANDOM lottery                                ' stir random value
  PAUSE 10

Cycle_Leds:
  ledTimer = ledTimer + 1
  IF ledTimer < 25 THEN Check_Trigger           ' 25 * 10 ms = 250
    ledPntr = ledPntr + 1 // 3
    LOOKUP ledPntr, (%001, %010, %100), PINS
    ledTimer = 0

Check_Trigger:
  timer = timer + 10 * PIR                      ' advance/clear timer
  IF timer < 300 THEN Main                      ' wait for valid signal

Prop_Ctrl:

  PINS = %000000000                             ' clear leds

  Fog   = IsOn

  PAUSE 1500

  Light = IsOn

  PAUSE 1500

  Cyl   = IsUp

  PAUSE 1500

  Fog   = IsOff

  PAUSE 2500

  Cyl   = IsDn

  PAUSE 3000

  Cyl   = IsUp

  PAUSE 4000

  Cyl   = IsDn

  PAUSE 2000

  Light = IsOff

  GOTO Reset


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


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


' -----[ User Data ]-------------------------------------------------------

JonnyMac

Looks okay -- does it work?  That's all that really matters.   ;D
Jon McPhalen
EFX-TEK Hollywood Office

tj

i ended up at if "pir < 500 then main" to settle it down but seems to work here.