#define sensorPin D10 const int rLED = D8; // red LED int motionState = LOW; // we start and assuming no motion detected int val = 0; // valuable for reading the pin status void setup() { Serial.begin(9600); pinMode(sensorPin, INPUT); pinMode(rLED, OUTPUT); } void loop() { val = digitalRead(sensorPin); // read RCWL value if (val == HIGH) { // chec if the input is HIGH digitalWrite(rLED, HIGH); // turn LED on if (motionState == LOW) { Serial.println("Motion detected!"); // print on output change motionState = HIGH; } } else { digitalWrite(rLED, LOW) ; // turn LED off if (motionState == HIGH) { Serial.println("Motion ended"); // print on output change motionState = LOW ; } } }