Where to add delay??

Hi folks

I have a system on the the go that uses a pir to activate a relay that switches on a light for a specific amount of time.

What i want to do now is add some delay so that when the light goes off. It can't be activated again for 15s.

The question is where do i add the delay -

Code -

const int pirPin = 2;     
const int relayPin =  13;      

int pirState = 0;         

void setup() {
  
  pinMode(relayPin, OUTPUT);      
  
  pinMode(pirPin, INPUT);     
}

void loop(){

  pirState = digitalRead(pirPin);

  
  if (pirState == HIGH) {     
    digitalWrite(relayPin, LOW);
    delay(110200);
    digitalWrite(relayPin, HIGH);

  } 
  else {
    digitalWrite(relayPin, HIGH); 
    

  }
}

fasterthanlight: What i want to do now is add some delay so that when the light goes off. It can't be activated again for 15s.

Right after you turn it off?

fasterthanlight: Hi folks

I have a system on the the go that uses a pir to activate a relay that switches on a light for a specific amount of time.

What i want to do now is add some delay so that when the light goes off. It can't be activated again for 15s.

The question is where do i add the delay -

Please do not use delay()

Rather look at the Blink Without Delay example in the Arduino IDE and use that technique. Essentially you will set a long variable to current millis() and add 15000 to it. Then you will check in the loop for the current time to exceed that value and act accordingly. Some caveats, so search the forum for notes.

Here: http://forum.arduino.cc/index.php?topic=223286.0

const int pirPin = 2;     
const int relayPin =  13;      

void setup() 
{  
  pinMode(relayPin, OUTPUT);      
  pinMode(pirPin, INPUT);     
}

void loop()
{  
  if (digitalRead(pirPin))//guesing pir being HIGH means your pir was tripped? please comment 
  { // if(the pirPin is HIGH) aka "true" or "1" or anything besides zero    
    digitalWrite(relayPin, LOW);//turn your light off or on? assuming on given detection 
    delay(110200); // delay after detection, presumably so someone can see where they are going or something
    digitalWrite(relayPin, HIGH);// turn light off ?? 
    delay(15000);// delay afterwards preventing anything else happening
  } 
}

Delay will become the bane of your existence if you are into this for any amount of time, so I agree with the statement above. Figure out how to get rid of them ASAP as practice, its worth it.