Pages: [1]   Go Down
Author Topic: Motion Sensor Interference Problem?  (Read 481 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

so I have this very simple motion sensor module from an unknown company.

The basic pinout is 5V GND and an output which sets to high when motion is detected. I have set the mode to high, so that the sensor triggers only once when continuous motion is detected and does not alternate between low and high. I have hooked this up to the arduino and read the output over a digital input pin. Basically, when motion is detected, a buzzer goes off and an LED lights up. Everything seems to work fine when the led is simply turned on and off when motion is detected but I thought this was boring and wanted to have it flash repeatedly when motion is detected. However, when I do this, the sensor gets set to high constantly and never sets the output to low again. The strange thing is that when done with the buzzer there is no problem!  So I went back to the constantly lit LED approach but now wanted to have the LED flash every 5 seconds for approximately 15ms to indicate that everything is running when the sensor output is low. However, as soon as the LED lights up for the 15ms, the sensor triggers and gets set to high. At first I thought this was the light of the LED tripping the sensor, but I have run the thing completely separated, even inside a box and I still have the problem!   Using the LED on pin 13 as the indicator seems to work better, but every 2nd to 3rd flash triggers the sensor and sets it to high.

I have no explanation what so ever for this and am really hoping that someone has an idea on how to solve this?

I thought it was just noise or a power issue at first but I have tried using resistors as well as capacitors and the situation does not improve.

I don't want to run the sensor and the arduino on different power supplies and use an optocoupler unless this is absolutely necessary, although I don't even know if that would solve the problem either...

I would greatly appreciate any guidance with this matter! 


Thanks! 
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5400
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Post your code. My crystal ball is still in the shop waiting for parts.  smiley-wink
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46299
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
i=digitalRead(A0);
Why does this value need to be stored in a global variable?

Code:
if(i>0){       
digitalWrite(6,HIGH);
digitalWrite(12,HIGH);
}
if(i<1){
It makes more sense to test for == HIGH or LOW, not greater than or less then 0 or 1.

Incrementing count on every pass through loop doesn't make sense. Incrementing it only when the sensor reads HIGH or LOW, whichever indicates motion, does.

Turning the buzzer and LED on when the state of the sensor IS HIGH or LOW does not make sense. Turning them on or off when the state changes makes sense. Starting the counter when the state changes makes sense.

Then, you can toggle the LED pin, periodically, as in the blink without delay example, when the state is "motion detected".
Logged

Queensland, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino is fun... especially when breadboarded!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

It appears that the OP and I both have the same problem, and is being trigged by the same desire to want a blinking LED instead of a just a LED lighting up when there is motion and going out when there is none.

As it is part of a larger project, I've cut the code down, with just the motion detect and blinky led. The *false positive* is still present, and goes away if I comment out either of the below lines. Motion sensor works fine in a sketch that simply makes the LED go high when the sensor is high, and low when the sensor is low. Motion sensor (a generic one) is wired to port 9 with a 10k pullup resistor.

Code:
digitalWrite(PWR_STATUS_PIN,pwrPinState); //change led state

Code:
Serial.print("pwrPin: "); Serial.println(pwrPinState,DEC);

Any ideas or suggestions would be appreaiated, as the current "solution" to the problem is to simply comment out the blink code and forget about it... smiley

Cheers,
Peter

Code:
#define PIR_PIN 9

#define PWR_STATUS_PIN A0
#define PIR_STATUS_PIN A3

#define PIR_INIT_DELAY 30000

boolean pirInit = false;
boolean motion = false;
boolean pirState = LOW;
boolean pwrPinState = LOW;

// timers
uint32_t timerPower;

// delay interval
uint16_t intervalPower = 201;

void setup()
{
  Serial.begin(9600);
  Serial.println("Nightlight initialising...");

  pinMode(PIR_PIN,INPUT);

  pinMode(PIR_STATUS_PIN, OUTPUT);
  pinMode(PWR_STATUS_PIN,OUTPUT);
}

void loop()
{
  uint32_t currentMillis = millis();

  //pretty 2 blinks every 2 seconds
  if ((currentMillis - timerPower) > intervalPower)
  {
    if (intervalPower == 201)
    {
      intervalPower = 101;
      pwrPinState = LOW;
    }
    else if (intervalPower == 101)
    {
      intervalPower = 202;
      pwrPinState = HIGH;
    }
    else if (intervalPower == 202)
    {
      intervalPower = 1496;
      pwrPinState = LOW;
    }
    else if (intervalPower == 1496)
    {
      intervalPower = 201;
      pwrPinState = HIGH;
    }    
    
    digitalWrite(PWR_STATUS_PIN,pwrPinState); //change led state

    Serial.print("pwrPin: "); Serial.println(pwrPinState,DEC);

    timerPower = currentMillis;               //reset timer
  }


  if (currentMillis > PIR_INIT_DELAY && !pirInit)
  {
    pirInit = true;
    Serial.println("PIR init delay elapsed... ");  
  }
  
  motion = digitalRead(PIR_PIN);  // read input value
  
  if (motion == HIGH && pirInit)                //if motion detected, and init time lapsed ...
  {
    digitalWrite(PIR_STATUS_PIN, HIGH);         //turn PIR status led ON
    
    pirState = HIGH; //so we know we've already triggered
  }
  else                                         //else PIR motion event has ended
  {
    digitalWrite(PIR_STATUS_PIN, LOW);         //turn PIR status led OFF

    if (pirState == HIGH)                      //if PIR *was* high (thus will have just turned off)
    {

     Serial.println("Motion ended!");
     pirState = LOW;                          //reset PIR state back to low
    }
  }  
}
« Last Edit: April 17, 2013, 06:36:37 am by pfeerick » Logged

Pages: [1]   Go Up
Jump to: