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.