Multiple action or loop for pir sensors? I need help

Hi Im new with arduino and Im creating new project with arduino uno
Project name is stairs light with two pir sensor…

Im using 2 pir sensor one of is upstairs (pirPin2) other one is downstairs (pirPin)

if pirPin detect a movement lights goes on to upstairs and pirPin2 detect a movement lights goes off from down to upstairs.

I know this is very basic, maybe silly but my question is how can I reverse this loop? I cant add second loop or something like this

so Ineed help for this I want to do this if pirPin2 detect any movement lights goes on to downstairs and pirPin detect any movement lights goes to down from up.

My codes are below you can see my codes

I hope its clear if you could help me I will be happy

=========================================================
int calibrationTime = 10;       

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

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

boolean lockLow = true;
boolean takeLowTime; 

int pirPin = 7;    //the digital pin connected to the PIR sensor's output
int ledPin1 = 8;
int ledPin2 = 9;
int ledPin3 = 13;
int ledPin4 = 12;
int ledPin5 = 11;
int pirPin2 = 6;



/////////////////////////////
//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(pirPin2, INPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  digitalWrite(pirPin2, LOW);
  digitalWrite(pirPin, LOW);
 

  //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(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin1, HIGH);
       delay(200);
       digitalWrite(ledPin2, HIGH); 
       delay(200);
       digitalWrite(ledPin3, HIGH);
     delay(200);
   digitalWrite(ledPin4, HIGH);
 delay(200);
digitalWrite(ledPin5, HIGH); }
       if(lockLow){ 
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;           
         Serial.println("---");
         Serial.print("motion detected at pirPin2 ");
         Serial.print(millis()/1000);
         Serial.println(" sec");
         delay(50);
         }         
         takeLowTime = true;
       

     if(digitalRead(pirPin2) == HIGH){       
       digitalWrite(ledPin1, LOW);
     delay(500);  //the led visualizes the sensors output pin state
digitalWrite(ledPin2, LOW);
delay(500);
digitalWrite(ledPin3, LOW);
delay(500);
digitalWrite(ledPin4, LOW);
delay(500);
digitalWrite(ledPin5, LOW);}
     
       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = 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(!lockLow && millis() - lowIn > pause){ 
           //makes sure this block of code is only executed again after
           //a new motion sequence has been detected
           lockLow = true;                       
           Serial.print("motion ended at ");      //output
           Serial.print((millis() - pause)/1000);
           Serial.println(" sec");
           delay(50);
           }
       
}

Im using 2 pir sensor one of is upstairs (pirPin2) other one is downstairs (pirPin)

That makes sense. I'd have used dumb names like pirPinUp and pirPinDn.

if pirPin detect a movement lights goes on to upstairs and pirPin2 detect a movement lights goes off from down to upstairs.

I'm not following. Do you have a series of lights connected to pins that are turned on at intervals?

I know this is very basic, maybe silly but my question is how can I reverse this loop? I cant add second loop or something like this

You can have one function that turns the pins on in one order, and another that turns them on in the reverse order. Call whichever is appropriate. Actually, with a little effort, you can have one function that you pass a positive or negative value to, depending on which pin goes high first.

Code needs to be posted correctly. Read the stickies at the top of the forum that you were supposed to read before posting here.

Thanks for your reply
and ? have fixed code area

Hi,

I have found rights code for my project but its using with buttons I want to change this buttons to pir sensor I tried it but I think I missed something how can I change this

  //LED pin assignments
  int led1 = 2;
  int led2 = 3;
  int led3 = 4;
  int led4 = 5;
  int led5 = 6;
  int led6 = 7;
  int led7 = 8;
  int led8 = 9;
  int led9 = 10;
  
  // button pin assignments
  int b_up = 11; //button at bottom of stairs
  int b_down = 12; //button at top of stairs

  //LED delay settings
  int tOn = 400; //LED On delay
  int tOff = 750; //LED Off delay
  int del = 0; //Delay after action (used for debugging - set to 500-1000 to introduce a delay between each action)
  
  //variables
  static unsigned activeup = 0; //whether the system is active going upwards
  static unsigned activedown = 0; //whether the system is active going downwards
  
void setup() { //make with the setups
  
  //Set Serial
  Serial.begin(9600);
  Serial.println("");
  Serial.println("Activated");
  delay(del);
  
  //Set LED pins as output
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
  pinMode(led8, OUTPUT);
  pinMode(led9, OUTPUT);
  
  //Set button pins as input
  pinMode(b_up, INPUT_PULLUP);
  pinMode(b_down, INPUT_PULLUP);
  
  Serial.println("Pins set");
  delay(del);
  
  //Clear variables
  int activedown = 0;
  int activeup = 0;
  
  //Print variables to Serial
  Serial.print("active up: ");
  Serial.println(activeup);
  Serial.print("active down: ");
  Serial.println(activedown);
  delay(del);
  
  Serial.println("Variables set");
  delay(del);
  
  Serial.println("");
  Serial.println("Ready");
}


void loop() {  //forever in your loopings
      
      //Set variables based on pin state
      int up = digitalRead(b_up);
      int down = digitalRead(b_down);
    
      Serial.print("active up: ");
      Serial.println(activeup);
      Serial.print("active down: ");
      Serial.println(activedown);
      delay(del);
    
  if (up == LOW){ //Bottom button pressed
    
      Serial.println("Bottom button pressed!");
      delay(del);
      
      //Set variables
      Serial.print("active up: ");
      Serial.println(activeup);
      Serial.print("active down: ");
      Serial.println(activedown);
      delay(del);
      
          if (activeup == 1 || activedown == 1){ //checks if system active
                
                //If active
                Serial.println("System active!");
                delay(del);
                
                OffDown(); //function call
                        
          } else { 
            
            //if not active            
            Serial.println("System activated (up)");
            delay(del);
      
            OnUp(); //function call
            
          }
      
      
  }
     
  if (down == LOW){
      
      Serial.println("Top button pressed");
      delay(del);
      
      Serial.print("active up: ");
      Serial.println(activeup);
      Serial.print("active down: ");
      Serial.println(activedown);
      delay(del);
      
      if (activeup == 1 || activedown == 1){
            
                Serial.println("System active!");
                delay(del);
                
                OffUp(); //function call
                        
          } else  {
        
            Serial.println("System activated (down)");
            delay(del);
      
            OnDown(); //function call
            
          }
       
  }

        
}

void OnUp(){ //Switches lights on going up
  
  Serial.println("Switching on lights (up)");
               delay(del);
               
               //set LEDs on in turn
               digitalWrite(led1, HIGH);
               delay(tOn);
               digitalWrite(led2, HIGH);
               delay(tOn);
               digitalWrite(led3, HIGH);
               delay(tOn);
               digitalWrite(led4, HIGH);
               delay(tOn);
               digitalWrite(led5, HIGH);
               delay(tOn);
               digitalWrite(led6, HIGH);
               delay(tOn);
               digitalWrite(led7, HIGH);
               delay(tOn);
               digitalWrite(led8, HIGH);
               delay(tOn);
               digitalWrite(led9, HIGH);
               
               activeup = 1; //Set system as active up
               
               Serial.print("active up: ");
               Serial.println(activeup);
               Serial.print("active down: ");
               Serial.println(activedown);
               delay(del);
               
               Serial.println("System now active (up)");
               delay(del);
                               
} //end OnUp

void OffUp(){ //switches lights off going up
  
         Serial.println("Switching lights off (Up)");
         delay(del); 
           
         
         //sets LEDs off in turn
         digitalWrite(led1, LOW);
         delay(tOff);
         digitalWrite(led2, LOW);
         delay(tOff);
         digitalWrite(led3, LOW);
         delay(tOff);
         digitalWrite(led4, LOW);
         delay(tOff);
         digitalWrite(led5, LOW);
         delay(tOff);
         digitalWrite(led6, LOW);
         delay(tOff);
         digitalWrite(led7, LOW);
         delay(tOff);
         digitalWrite(led8, LOW);
         delay(tOff);
         digitalWrite(led9, LOW);
         
         //set system as being off
         activeup = 0;
         activedown = 0;
         
         Serial.print("active up: ");
         Serial.println(activeup);
         Serial.print("active down: ");
         Serial.println(activedown);
         delay(del);
         
         Serial.println("System not active");
         delay(del);
         
} //End OffUp

void OnDown(){ //switches lights on going down
  
         Serial.println("Switching lights on (down)");
         delay(del);
               
         //set LEDs on in turn
         digitalWrite(led9, HIGH);
         delay(tOn);
         digitalWrite(led8, HIGH);
         delay(tOn);
         digitalWrite(led7, HIGH);
         delay(tOn);
         digitalWrite(led6, HIGH);
         delay(tOn);
         digitalWrite(led5, HIGH);
         delay(tOn);
         digitalWrite(led4, HIGH);
         delay(tOn);
         digitalWrite(led3, HIGH);
         delay(tOn);
         digitalWrite(led2, HIGH);
         delay(tOn);
         digitalWrite(led1, HIGH);
         
         activedown = 1; //sets system as active down
         
         Serial.print("active up: ");
         Serial.println(activeup);
         Serial.print("active down: ");
         Serial.println(activedown);
         delay(del);
         
         Serial.println("System now active (down)");
         delay(del);
  
} //End OnDown

void OffDown(){ //switches lights off going down
  
       Serial.println("Switching lights off (down)");
       delay(del);       
       
       //sets LEDs off in turn
       digitalWrite(led9, LOW);
       delay(tOff);
       digitalWrite(led8, LOW);
       delay(tOff);
       digitalWrite(led7, LOW);
       delay(tOff);
       digitalWrite(led6, LOW);
       delay(tOff);
       digitalWrite(led5, LOW);
       delay(tOff);
       digitalWrite(led4, LOW);
       delay(tOff);
       digitalWrite(led3, LOW);
       delay(tOff);
       digitalWrite(led2, LOW);
       delay(tOff);
       digitalWrite(led1, LOW);
       
       //set system as not active
       activedown = 0;
       activeup = 0;
       
       Serial.print("active up: ");
       Serial.println(activeup);
       Serial.print("active down: ");
       Serial.println(activedown);
       delay(del);
       
       Serial.println("System not active");
       delay(del);     

  
}//End OffDown