#define LED_PIN 3
#define PIR_PIN 4
int switchState = 0;
unsigned long lastTime = 0;
int intervalOn = 1000;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(PIR_PIN, INPUT);
}
void loop () {
bool motion = digitalRead(PIR_PIN);
if (motion && !switchState) {
switchState = motion;//remember
digitalWrite(LED_PIN, HIGH);
} else if (!motion && switchState) {
if (millis() - lastTime >= intervalOn)
{
lastTime = millis();
switchState = false;
digitalWrite(LED_PIN, LOW);
}
}
}