// For: https://forum.arduino.cc/t/simple-motion-sensor-output-issue/993654
int PowerPin = 2;
int sensor = 3;
int state = LOW;
int val = 0;
void setup()
{
//get power to the sensor through node 2
pinMode(PowerPin, OUTPUT);
digitalWrite(PowerPin, HIGH);
//pinMode(sdcard, OUTPUT);
pinMode(sensor, INPUT);
Serial.begin(9600);
}
void loop()
{
val = digitalRead(sensor);
if (val == HIGH)
{
if (state == LOW)
{
Serial.println("MOTION DETECTED!");
state = HIGH;
}
}
else
{
if (state == HIGH)
{
Serial.println("no more motion");
state = LOW;
}
}
}