PIR sensor won't quit

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
allears
 
Posts: 26
Joined: Mon Sep 05, 2011 5:13 pm

PIR sensor won't quit

Post by allears »

I have connected the basic PIR sensor (Product ID#189) as directed, to an Arduino Uno, and loaded your sample test script:

Code: Select all

/*
     * PIR sensor tester
     */
     
    int ledPin = 13;                // choose the pin for the LED
    int inputPin = 4;               // choose the input pin (for PIR sensor)
    int pirState = LOW;             // we start, assuming no motion detected
    int val = 0;                    // variable for reading the pin status
     
    void setup() {
      pinMode(ledPin, OUTPUT);      // declare LED as output
      pinMode(inputPin, INPUT);     // declare sensor as input
      digitalWrite(inputPin, HIGH);
     
      Serial.begin(9600);
    }
     
    void loop(){
      val = digitalRead(inputPin);  // read input value
      if (val == HIGH) {            // check if the input is HIGH
        digitalWrite(ledPin, HIGH);  // turn LED ON
        if (pirState == LOW) {
          // we have just turned on
          Serial.println("Motion detected!");
          // We only want to print on the output change, not state
          pirState = HIGH;
        }
      } else {
        digitalWrite(ledPin, LOW); // turn LED OFF
        if (pirState == HIGH){
          // we have just turned of
          Serial.println("Motion ended!");
          // We only want to print on the output change, not state
          pirState = LOW;
        }
      }
    }
Even when the sensor is adjusted for lowest sensitivity, and shut up in a box, it continually indicates that motion has been detected (about every 2-3 seconds), and then that motion has stopped. It cycles over and over, no matter what's going on in its vicinity. I can't get it to shut up, no matter how still the surroundings.
Any suggestions appreciated.
Last edited by Franklin97355 on Fri Jun 23, 2017 8:38 pm, edited 1 time in total.
Reason: Changed quotes to code tags.

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: PIR sensor won't quit

Post by zener »

Connect a volt meter to the input pin of the Arduino, and ground (red lead to pin 4 and black lead to ground pin on the Arduino). See what the voltage is actually doing there and report back.

User avatar
caitlinsdad
 
Posts: 627
Joined: Fri Feb 24, 2012 4:23 pm

Re: PIR sensor won't quit

Post by caitlinsdad »

When I used a PIR sensor a long time ago I remembered that it had to "warm up" before use.
http://playground.arduino.cc/Code/PIRsense
It may be a slow responding type of sensor where you have to treat it like a switch and "debounce" or wait to determine a solid on or off. The immediate looping might be sensing a false trigger. Good luck.

allears
 
Posts: 26
Joined: Mon Sep 05, 2011 5:13 pm

Re: PIR sensor won't quit

Post by allears »

It shows .18 VDC when off, 2.86 when on.
I also noticed that when it initialized, it was off, until I triggered it by making a movement near a crack in the box where I've put the sensor. At that point, it started cycling off and on, and continuing to do so whether there was any further motion or not.

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: PIR sensor won't quit

Post by zener »

Please post a photo showing your wiring and connections. I think 800x600 resolution is recommended. It shouldn't be doing that.

allears
 
Posts: 26
Joined: Mon Sep 05, 2011 5:13 pm

Re: PIR sensor won't quit

Post by allears »

Here's a picture, hope it's detailed and focused enough. You can see the handy-dandy box I've been using to try to cover the sensor.
Attachments
PIR_Hookup.JPG
PIR_Hookup.JPG (353.06 KiB) Viewed 311 times

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: PIR sensor won't quit

Post by zener »

I am guessing it might be a power issue. There is some "devil in the details" here. You are powering the PIR from the 5V pin of the UNO, which is being powered by your USB cable which is being powered by your computer. The USB is nominally 5V, and the 5V pin says 5V right on it, and the PIR says it can run from 5-12V. So in theory this should work. But maybe not quite.

I would run the same test as before, except this time put the meter probes on the black and red wires to the PIR. See if you get 5V all the time or what you get.

allears
 
Posts: 26
Joined: Mon Sep 05, 2011 5:13 pm

Re: PIR sensor won't quit

Post by allears »

Bingo! That was it. I didn't even hook up a meter, just powered the Arduino from a 12v wall wart instead of the USB connection, and it started behaving normally.
Much thanks for your help. Solved my problem, and now I know something to watch out for in the future.

Regards,

Marc

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”