Go Down

Topic: Motion Sensor Interference Problem? (Read 1 time) previous topic - next topic



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! 



Post your code. My crystal ball is still in the shop waiting for parts.  ;)


Code: [Select]
Why does this value need to be stored in a global variable?

Code: [Select]

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".
The art of getting good answers lies in asking good questions.


Apr 17, 2013, 01:34 pm Last Edit: Apr 17, 2013, 01:36 pm by pfeerick Reason: 1

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: [Select]
digitalWrite(PWR_STATUS_PIN,pwrPinState); //change led state

Code: [Select]
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... :)


Code: [Select]

#define PIR_PIN 9


#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.println("Nightlight initialising...");



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

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131