Shop OBEX P1 Docs P2 Docs Learn Events
PIR Problem Help Please — Parallax Forums

PIR Problem Help Please

robomakerrobomaker Posts: 12
edited 2013-06-28 13:15 in General Discussion
I am trying to use a PIR sensor to delay action until motion is detected. However it seems to send a HIGH signal right away and does not wait for motion;
I am using this code at the beginning of my program but it always produces no motion pause. What am I doing wrong?

Do
IF IN4 = 1 Then GOTO Start
LOOP

Start;
REST OF PROGRAM...........

IN4 Seems to always be at 1

What gives? Any help would be greatly appreciated. Hope I don't seem too stupid

Comments

  • Shawn LoweShawn Lowe Posts: 635
    edited 2013-06-27 07:30
    PIR sensors, while convenient, are notoriously finicky. Put a delay in your code of 30 seconds to give the pir a chance to stabalize. Then you might want to put a field restrictor on the PIR if you can.
  • bill190bill190 Posts: 769
    edited 2013-06-27 07:35
    Have you used a multimeter to read IN4?

    Is the PIR powered up at the same time the microcontroller is powered up? Try powering up the PIR by itself and see what it does / how it works.

    Try disconnecting the PIR from IN4 and see what happens.
  • robomakerrobomaker Posts: 12
    edited 2013-06-27 13:17
    Thanks for the input. I have tried the "warm-up" delay but didn't seem to help. As for separate power up I will have to look into that. Thanks again and will let you know if I get her going.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-06-27 13:25
    Where is the PIR sensor mounted?
  • Jeff HaasJeff Haas Posts: 421
    edited 2013-06-27 15:27
    Robomaker,

    You didn't mention which processor you're on, but here's some sample code for the Basic Stamp 1, originally from EFX-Tek, that could help. Note the section right after MAIN that debounces the PIR input, it makes a big difference.
    ' =========================================================================
    '
    ' File...... PIR.BS1
    '
    ' Purpose...Test PIR by blinking an LED.  
    ' Date: 6/24/2012
    '
    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    '
    ' =========================================================================
    ' -----[Connections]--------
    ' LED is on OUT0: OUT0 -> 510K -> LED (flat) -> LED (anode) -> V+
    ' PIR data is on PIN 6.
    
    ' -----[ I/O Definitions ]-------------------------------------------------
    
    SYMBOL    PIR = PIN6       
    
    ' -----[ Constants ]-------------------------------------------------------
    
    SYMBOL    IsOn = 1         ' for active-high in/out
    SYMBOL    IsOff = 0
    SYMBOL    ScanDelay = 10   ' 10 ms scan delay
    
    ' -----[ Variables ]-------------------------------------------------------
    
    SYMBOL pirTimer = B2       ' for debouncing
    SYMBOL Led = 0
    
    ' -----[ Initialization ]--------------------------------------------------
    
    Reset:
      PAUSE 20000              ' warm-up delay
      pirTimer = 0             ' clear timer for scan
    
      HIGH Led                   ' Blink LED to show warmup is over
      PAUSE 500
      LOW Led
    
    ' -----[ Program Code ]----------------------------------------------------
    
    Main:
    
      PAUSE ScanDelay
      pirTimer = pirTimer + ScanDelay * PIR   ' advance/clear timer
      IF pirTimer < 250 THEN Main
    
      HIGH Led                   ' Blink LED to show motion detected
      PAUSE 500
      LOW Led
      PAUSE 500
      HIGH Led
      PAUSE 500
      LOW Led
      PAUSE 8000                 ' Let PIR cool down.  New mini models need 8 seconds to keep from retriggering.
    
      ' control code here
    
    GOTO Main
    
  • WhitWhit Posts: 4,191
    edited 2013-06-27 16:28
    Take a look at this - http://learn.parallax.com/KickStart/555-28027 I think if you can get this going - you will probably figure out your situation. This is great resource!
  • garyggaryg Posts: 420
    edited 2013-06-28 09:38
    I've used Parallax PIR sensor in a couple of outdoor projects.
    These are facts from my past projects.
    PIR sensor needs to be powered up always, if not it will need about a one minute warmup.
    PIR sensor, once warmed up consumes almost no power. I've had 4 AA batteries last for 6 months.
    PIR sensor output is active high whenever the red LED in the sensor is On.
    PIR sensor will see through plastic milk carton material. I use 1/2 gallon milk carton for weather proofing.
    PIR sensor is very sensistive to sunlight when output is set to the default of long range.

    I hope these facts help you.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-06-28 10:02
    garyg wrote: »
    I've used Parallax PIR sensor in a couple of outdoor projects.
    These are facts from my past projects.
    PIR sensor needs to be powered up always, if not it will need about a one minute warmup.
    PIR sensor, once warmed up consumes almost no power. I've had 4 AA batteries last for 6 months.
    PIR sensor output is active high whenever the red LED in the sensor is On.
    PIR sensor will see through plastic milk carton material. I use 1/2 gallon milk carton for weather proofing.
    PIR sensor is very sensistive to sunlight when output is set to the default of long range.

    I hope these facts help you.

    garyg,

    I just wanted to touch on one point in your comments for clarity on PIR sensor operation. You noted that the PIR sensor is very sensitive to sunlight in the long range mode. It's not the light that it is sensitive to. If you're using a clear material to weatherproof the sensor you may be experiencing a mild greenhouse effect caused by sunlight passing through the material and striking a surface converting some of the energy into radiated heat energy, which is then trapped inside the material. This is how your car heats up so much inside wen sitting in the sun. So the PIR is responding to the changes in heat as it should. Without the weatherproof material it should not be doing that though, unless picking up radiated heat from a surface, such as you might see radiated heat from asphalt on a sunny day.
  • garyggaryg Posts: 420
    edited 2013-06-28 12:44
    Chris
    Point Noted and well taken.
    On my outdoor project, I've fabricated a sunshield, similar to a baseball cap bill.
    I painted the inside of my housing black
    I also set my PIR on the 15ft less sensitive setting.
    The milk carton material is somewhat translucent, but basically clear.
    I'll need to observe my owl project over a day or two to see if the misfires due to heat on my
    milk carton window disappear. The thing actually works very good after sunset.

    I hope this discussion helps out Robomaker.
    A good understanding of how these sensors actually works is very helpful in general.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-06-28 13:15
    garyg wrote: »
    Chris
    Point Noted and well taken.I hope this discussion helps out Robomaker.
    A good understanding of how these sensors actually works is very helpful in general.

    Yes, that was my hope as well. Like any sensor, things can vary based on environment, location, enclosure, etc. So sometimes experimentation is necessary.
Sign In or Register to comment.