Problem to restart condition everytime PIR detects movement

What can I do, to make condition 2 to restart including the time "delay (10000);" , every time Sensor PIR detects movement (true) ? Please help

int led = 13;
int pin = 3;

int value = 0;
int pinState = LOW;

void setup() {
pinMode(led, OUTPUT);
pinMode(pin, INPUT);
Serial.begin(9600);

}

void loop() { //(Condition 1)

value = digitalRead(pin);
if (value == true) {
  pinState = true;
  digitalWrite(led, HIGH);
  Serial.println("Motion Detected!");
  delay(1000);


}//Condition 2

    value = digitalRead(pin);
    
     while(pinState == true) {
      Serial.println("Motion Still Detected!");
      delay(10000);

//here is the problem
//What can I do, to make condition 2 to restart including the time "delay (10000);" , every time Sensor PIR detects movement? Please help

    }
}

}

  if (pinState == HIGH) {
    pinState = false;
    Serial.println("Motion ended");
    digitalWrite(led, LOW);

}

How about reading the pin again?

Please remember to use code tags when posting code.

Yes I can do that but, still not fix my problem :frowning:

What I am trying to do is that in the moment when the PIR detects movement, the condition restart immediately.

Would getting rid of the big delays help?

If I rid of the big delay then, sensor PIR it will not have time to detect movement again and it will go to false immediately, that is why I am putting big delay. So what I am trying to do is;

while(pinState == true) {
      Serial.println("Motion Still Detected!"); 
      delay(10000); // In this 10 seconds if  PIR detects movement restart with 10 seconds again

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.