Hello,
I am using RCWL-0516 sensor to detect motion and turn on Led. The code is working and turns on the Led. My issue is that it prints “Led On” continuously rather than just once when it turns on and then print turn off.
int Sensor = 2; //RCWL-0516 Input Pin
int led = 6; //LED Pin
void setup()
{
Serial.begin(9600);
pinMode(Sensor,INPUT);// motion sensor connected to analog 0
pinMode(led, OUTPUT);
//analogReference(DEFAULT);
}
void loop()
{
if (digitalRead(Sensor) == HIGH )
{
digitalWrite(led,HIGH);
Serial.flush();
Serial.println( "Led On" );
}
else {
digitalWrite(led, LOW);
Serial.println( "Led Off" );
}
}