two PIR

hi all

need some help with the following code

I have two PIRS to trigger some relays (PIR1 triggers the relays from 1 - 14 & PIR2 triggers the relays from 14 - 1 ) the problem is if you trigger the first PIR and then trigger the second it will trigger the next sequence.

what i need is if one PRI is LOW (relays on), the other cant detect motion and you have time to pass it

(hope that makes sense)

thanks

/the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;

//the time when the sensor outputs a low impulse
long unsigned int lowIn1;
long unsigned int lowIn2;   //PIR 2 added here

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 1000;

boolean lockLow1 = true;
boolean takeLowTime1;
boolean lockLow2 = true;    //PIR 2 added here
boolean takeLowTime2;

//(bottom) step 1 > 14
int pirPin1 = A5;    //the digital pin connected to the PIR sensor's output
int BOTTOMRELAY[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, A0, A1, A2}; // an array of pin numbers to which LEDs are attached


//(top) step 14 > 1
int pirPin2 = A4;    //PIR 2 added here
int TOPRELAY[] = {A2, A1, A0, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2}; // an array of pin numbers to which LEDs are attached

int pinCount = 14;           // the number of pins (i.e. the length of the array)
int timer = 500;


/////////////////////////////
//SETUP
void setup() {
  Serial.begin(9600);
  // step 1 > 14 (bottom)
  pinMode(pirPin1, INPUT);
  digitalWrite(pirPin1, LOW);
  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
    pinMode(BOTTOMRELAY[thisPin], OUTPUT);
  }

  // step 14 > 1 (top)
  pinMode(pirPin2, INPUT);  //PIR 2 added here
  digitalWrite(pirPin2, LOW);  //PIR 2 added here
  for (int thisPin2 = 0; thisPin2 < pinCount; thisPin2++) {
    pinMode(TOPRELAY[thisPin2], OUTPUT);
  }


  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
  for (int i = 0; i < calibrationTime; i++) {
    Serial.print(".");
    delay(1000);
  }
  Serial.println(" done");
  Serial.println("SENSOR ACTIVE");
  delay(50);

}

////////////////////////////
//LOOP
void loop() {

  //If input 1 is HIGH

  if (digitalRead(pirPin1) == HIGH) {
    for (int thisPin = 0; thisPin < pinCount; thisPin++) {
      // turn the pin on:
      digitalWrite(BOTTOMRELAY[thisPin], LOW);
      delay(175);
    }
    {
       delay (10000); //delay in on time before turning off
    }
    if (lockLow1) {
      //makes sure we wait for a transition to LOW before any further output is made:
      lockLow1 = false;
      Serial.println("---");
      Serial.print("motion detected at1 ");
      Serial.print(millis() / 1000);
      Serial.println(" sec");
      delay(50);
    }
    takeLowTime1 = true;
  }
  

  //If input 1 is LOW

  if (digitalRead(pirPin1) == LOW) {
    for (int thisPin = 0; thisPin < pinCount; thisPin++) {
      // turn the pin on:
      digitalWrite(BOTTOMRELAY[thisPin], HIGH);
      delay(175);
    }
    if (takeLowTime1) {
      lowIn1 = millis();          //save the time of the transition from high to LOW
      takeLowTime1 = false;       //make sure this is only done at the start of a LOW phase
    }
    //if the sensor is low for more than the given pause,
    //we assume that no more motion is going to happen
    if (!lockLow1 && millis() - lowIn1 > pause) {
      //makes sure this block of code is only executed again after
      //a new motion sequence has been detected
      lockLow1 = true;
      Serial.print("motion ended at1 ");      //output
      Serial.print((millis() - pause) / 1000);
      Serial.println(" sec");
      delay(50);
    }

  //If input 2 is HIGH

    
 if (digitalRead(pirPin2) == HIGH) {
    for (int thisPin2 = 0; thisPin2 < pinCount; thisPin2++) {
      // turn the pin on:
      digitalWrite(TOPRELAY[thisPin2], LOW);
      delay(175);
    }
    {
      delay (10000); //delay in on time before turning off
    }
    if (lockLow2) {
      //makes sure we wait for a transition to LOW before any further output is made:
      lockLow1 = false;
      Serial.println("---");
      Serial.print("motion detected at2 ");
      Serial.print(millis() / 1000);
      Serial.println(" sec");
      delay(50);
    }
    takeLowTime2 = true;
  }

    //If input 2 is LOW

 if (digitalRead(pirPin2) == LOW) {
    for (int thisPin = 0; thisPin < pinCount; thisPin++) {
      // turn the pin on:
      digitalWrite(TOPRELAY[thisPin], HIGH);
      delay(175);
      }
      if (takeLowTime2) {
        lowIn2 = millis();          //save the time of the transition from high to LOW
        takeLowTime2 = false;       //make sure this is only done at the start of a LOW phase
      }
      //if the sensor is low for more than the given pause,
      //we assume that no more motion is going to happen
      if (!lockLow2 && millis() - lowIn2 > pause) {
        //makes sure this block of code is only executed again after
        //a new motion sequence has been detected
        lockLow2 = true;
        Serial.print("motion ended at2 ");      //output
        Serial.print((millis() - pause) / 1000);
        Serial.println(" sec");
        delay(50);
      }
    }
   
  }
}

I see some very large delay() calls. That's a recipe for problems, and a highly unresponsive script.

Then, please explain exactly what the desired behaviour is (if trigger x, then output y - something like that) and how it differs from the actual behaviour of your script.