PIR Motion Sensor Issues

Hello,

I am trying different power optimizations on a parallax motion sensor connected to a xenon using the following code:

#define sensor D0                                                  
#define Vcc D1
void execute_periodically(){
    digitalWrite(Vcc, HIGH);
    delay(500);
    int data = digitalRead(sensor);
    delay(500);
    digitalWrite(Vcc, LOW);
    Particle.publish("Data", String(data));
     
}
Timer timer(1000*10, execute_periodically); 
void setup() {
    pinMode(Vcc, OUTPUT);
    pinMode(sensor, INPUT_PULLDOWN); //no change with pinMode(sensor, INPUT) or pinMode(sensor, INPUT_PULLUP)
    digitalWrite(Vcc, HIGH);
    timer.start();
}
void loop() {}

HERE’S MY ISSUE:
Everytime Vcc is set to high in the timer function, the PIR reads HIGH even when there is no motion. It looks like the PIR reads HIGH everytime it switches on. Any ideas as to why this might be happeneing and how I can fix this?

Appreciate the help.

From the datasheet you linked to:

The PIR Sensor requires a warm-up time in order to function properly. This is due to the settling time involved in “learning” its environment. This could be up to 40 seconds. During this time, the LEDs under the lens will be on and there should be as little motion as possible in the sensors field of view.

What happens if you actually adhere to the required warmup time? Does the output eventually go low?

4 Likes

Thanks, @ninjatill. I too read that in the datasheet shortly after I posted the question. I added a 1 minute delay before sampling the sensor data and it works fine.

1 Like