Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: GrooveHolmes on May 01, 2011, 02:59:50 PM

Title: Simple Arduino + Parallax PIR Motion sensor issue - electrical noise?!
Post by: GrooveHolmes on May 01, 2011, 02:59:50 PM
Hi folks!

Having a strange issue with my PIR motion sensor that I could use some suggestions on.

Note: I always give the sensor at least 30 seconds to calibrate, but now i'm up to 45. Also, I have the sensor inside of a cardboard tube (paper towel tube) to narrow and isolate the FOV from interference (works great).

The problem is the sensor, when hooked up to the arduino, seems to be experiencing something causing the sensor to return false triggers after the first true trigger. Confusing, so let me explain another way...

When I hook up the PIR sensor on the breadboard, feed a steady 4.5v (sensor needs anything between 3.3-5v), let the sensor calibrate, the output works correctly changing to HIGH upon motion, returning to low after a couple seconds of no motion. When there is no motion, the sensor is pretty good about being calm and not false triggering.  So this suggests the sensor is in good working order.


When i hook the sensor up to the arduino though (5v, PIR output --> Digital Pin 6) a problem surfaces; it will boot fine, initialize the sensor fine, and return no false readings UNTIL i trigger the sensor once with motion. The sensor will go HIGH (as it should), return LOW (as it should), then continue to oscillate between the two states every few (randomized) seconds as if there is some kind of weird loop or noise in the line.

Here's the code:
Code: [Select]
int IRpin = 6;
int LEDpin = 13;
int initialBoot = 1;
int IRstateCur = 0;
int IRstateLast = 0;



void setup() {               
  pinMode(LEDpin, OUTPUT);
  pinMode(IRpin, INPUT);
  digitalWrite(IRpin, LOW);
  digitalWrite(LEDpin, LOW); 
  Serial.begin(115200);
}

void loop() {
  if(initialBoot == 1){
    Serial.println("Initializing IR Motion Sensor, 45 seconds...");
    delay(25000);             
    Serial.println("20 seconds...");
    delay(10000);
    Serial.println("10 seconds...");
    delay(5000);
    Serial.println("5 seconds...");
    delay(5000);
    Serial.println("...initialized!");
    initialBoot = 0;
  }

  IRstateCur = digitalRead(IRpin);
  //Serial.println(IRstateCur);                   //use for debug, shows idle time between states
  //manage LED according to IRsensor
  if(IRstateCur == 0){
    digitalWrite(LEDpin, LOW);
    }else if(IRstateCur == 1){
      digitalWrite(LEDpin, HIGH);
    }
   
if(IRstateCur != IRstateLast && IRstateCur == 1){
  Serial.println("Motion detected");
  IRstateLast = 1;
  }else if(IRstateCur != IRstateLast && IRstateCur == 0){
    IRstateLast = 0;
  }
  delay(200);              // wait 200ms
}



If I enable that one line for debugging, it shows that the time between false triggers in NOT always equal, but seems kinda random. What I can say, is that it is NOT due to outside interference. I have successfully isolated the sensor in the tube, and cannot get it to 'falsely' trigger when on the bread board (very accurate).

Here's the output with the debug enabled:

(Sorry its so long, but it needs to be to show how the sequence is unfolding. at the beginning after initialization notice how there is no false output until the first motion event which was my hand in front of the sensor, after that, ALL other 'motions' detected are actually false and the oscillating problem I am describing.)


Code: [Select]
Initializing IR Motion Sensor, 45 seconds...
20 seconds...
10 seconds...
5 seconds...
...initialized!
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
Motion detected
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
1
Motion detected
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
Motion detected
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
1
Motion detected
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
Motion detected
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
Motion detected
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1


I've experimented with various 100-10K resistors on the IR sensor output to ground to try and remove any 'noise' while the output is LOW, but nay. Problem will not go away!!


What am I missing?!  ???  Thank you!
Title: Re: Simple Arduino + Parallax PIR Motion sensor issue - electrical noise?!
Post by: rbtying on May 01, 2011, 03:04:29 PM
The Parallax PIR sensor has a jumper on it that, when in a certain position, causes it to output an alternating high/low pulse train instead of a constant high.  Have you checked and made sure it's in the correct position?  It sounds like you've got the mode set incorrectly (check the datasheet).
Title: Re: Simple Arduino + Parallax PIR Motion sensor issue - electrical noise?!
Post by: GrooveHolmes on May 01, 2011, 04:36:31 PM
The Parallax PIR sensor has a jumper on it that, when in a certain position, causes it to output an alternating high/low pulse train instead of a constant high.  Have you checked and made sure it's in the correct position?  It sounds like you've got the mode set incorrectly (check the datasheet).

I've checked. It's on HIGH, which is the desired mode. But I've also tried it on LOW, same result; oscillating output, not triggered by any motion.
Title: Re: Simple Arduino + Parallax PIR Motion sensor issue - electrical noise?!
Post by: Soeren on May 01, 2011, 04:51:39 PM
Hi,

What am I missing?!
A stable and noise-free supply would be my guess. How is the decoupling made and with what components?

Please post a datasheet on your particular PIR unit.
Title: Re: Simple Arduino + Parallax PIR Motion sensor issue - electrical noise?!
Post by: GrooveHolmes on May 01, 2011, 07:45:32 PM
Using this PIR from Parallax:

http://www.parallax.com/dl/docs/prod/audiovis/pirsensor-v1.2.pdf (http://www.parallax.com/dl/docs/prod/audiovis/pirsensor-v1.2.pdf)

And this 'Freeduino' board from SolarRobotics:

http://www.solarbotics.com/products/28920/ (http://www.solarbotics.com/products/28920/)

And feeding the Freeduino with 6v from one of these (via 2.1mm DC plug):

http://www.altex.com/Philmore-Multi-Voltage-Regulated-DC-Power-Supply-MW122A-P143093.aspx (http://www.altex.com/Philmore-Multi-Voltage-Regulated-DC-Power-Supply-MW122A-P143093.aspx)
Title: Re: Simple Arduino + Parallax PIR Motion sensor issue - electrical noise?!
Post by: GrooveHolmes on May 01, 2011, 07:46:48 PM
That said, using the same DC power supply via my breadboard at 4.5v, the sensor works fine.

Title: Re: Simple Arduino + Parallax PIR Motion sensor issue - electrical noise?!
Post by: rbtying on May 01, 2011, 08:18:35 PM
I believe the Freeduino uses a standard (not LDO) regulator - it'll need more than ~7v to properly regulate.  Try feeding it 7.5v or 9v from your power supply and see if it helps.
Title: Re: Simple Arduino + Parallax PIR Motion sensor issue - electrical noise?!
Post by: GrooveHolmes on May 01, 2011, 08:54:02 PM
That was it. I put the input voltage to the Freeduino to 7.5V and its now working like it should. Odd, but it makes sense as the patterns did seem like the sensor was 'resetting/recalibrating'.

A few questions out of this now then...

1) Is this just a feature with this particular freeduino board, or is this an 'Arduino' thing (this is my first and only '*duino' product)? For $5 more i could buy an official board.
2) would a capacitor on the PIR power line help this (if the problem is due to a voltage drop)?
Title: Re: Simple Arduino + Parallax PIR Motion sensor issue - electrical noise?!
Post by: waltr on May 02, 2011, 09:37:26 AM
This is a feature of the linear regulator used on that board. The regulator has a minimum voltage drop of about 2.5V and can not provide a regulated output if its input voltage drops too low (5V out + 2.5V = 7.5V in). So if you supplied 6V in then the output would be about 6 -2.5 = 3.5V which is too low for the processor and PIR to work.

There are other linear regulators that are LDO (Low Drop Out) which as the description states has a lower drop up voltage. Some of these only need a 100 mV more on the input.