Indicator light programming

Hello Arduino forum,

On the face of it this is a somewhat complex question,
staircase_design_200528_600_x_400
but it is actually
fairly specific.

The context is a project called Staircase. Staircase uses PIRs (motion
detectors) to turn on LEDs as a walker moves up or down a staircase.
Line drawing attached.

If the lights all came on at once, or if the system worked the same
whether the walker were ascending or descending, the system would
be much simpler and would not need a microcontroller.
But because directionality is included
in the design the system must sense whether the walker is at
the top of the stairs and descending, or the converse.

There are seven lights and eight PIRs as arranged in the attached
line drawing titled 'Staircase Application PIR to Arduino to LEDs'

And so there has been written a sketch for Ascending, attached
and a sketch for Descending. Both sketches, after declaring variables
for the LEDs, the PIRS, the PIR states and the PIR inputs,
in the void setp() section, sets the PIRs as inputs and the LEDs as outputs.
Staircase_PIR_7_Ascending_220812.ino (5.6 KB)
Staircase_PIR_7_Descending_220812.ino (5.5 KB)
Staircase_PIR_7_w_directionality_220815.ino (8.1 KB)

The difference between the Ascending and Descending sketches
is in Ascending the PIR1 is read and PIR8 is omitted because there
is no duty above PIR 8 when ascending. And conversely in the Descending
sketch PIR1 is omitted because there is no light needed beneath
PIR1.

So a sketch, ...Directionality....ino was written with an If statement
included that says in psuedocode:
//after declarations and void setup()
//Descending use case
void loop() {
Read PIR1
If PIR1 is HIGH {
run the Ascending operation}
else {
run the Descending operation}
}

The sketch compiles and operates as designed.

The question is about the two LEDs that were included,
D1 and D2, and are in the sketch, at the end of the sketch,
just blinking on and off continuously.
D1 and D2 were included to be indicators of directionality.
That is, D1 would be on when the Ascending use case
was operating and D2 would be on when the Descending
use case was running.

But if D1 is turned on at the beginning of the
Ascending loop and turned off at the of the Ascending
statements, because the computer reads the statements
so quickly, the D1 would blink so briefly that it
would scarce be seen.

So how to make D1 come on for the time while the
PIRs are operating in the Ascending operation?
(and D2 come on for the time while the
PIRs are operating in the Descending operation?)

Thanks.

Allen Pitts
Dallas TX

Code ascending posted in code tags:

/***********************************************************************************
*  Staircase 7 PIR w D1 & D2 Sketch
* to test PCB Staircase 220308 Beta
* Based on Staircase_Blink_7_w_D1_D2_220810
* with parts based on 
* Staircase_7_Channel_w_heartbeat_and_D1_D2_220428
* and
* Staircase_7_Channel_w_heartbeat_and_D1_D2_220528_desc
************************************************************************************/
// ++++  LED pin numbers ledPinX Output 2-10 ++++
int ledPin1 = 2;
int ledPin2 = 3;
int ledPin3 = 4;
int ledPin4 = 5;
int ledPin5 = 6;
int ledPin6 = 7;
int ledPin7 = 8;
int ledPin9 = 9;   // green  D2
int ledPin10 = 10;  // red  D1

// ++++ Input pin numbers for PIR inputPinXX A5-A0, 11, 12 13 ++++
int inputPinA5 = A5;               // choose the input pin (for PIR sensor)
int inputPinA4 = A4; 
int inputPinA3 = A3; 
int inputPinA2 = A2; 
int inputPinA1 = A1;
int inputPinA0 = A0;
int inputPin11 = 11;                // 220504 acp
int inputPin12 = 12;
// int inputPin13 = 13;

// ++++ PIR State pirStateXX = LOW ++++
int pirStateA5 = LOW;             // start, assuming no motion detected
int pirStateA4 = LOW;
int pirStateA3 = LOW;
int pirStateA2 = LOW; 
int pirStateA1 = LOW;
int pirStateA0 = LOW;
int pirState11 = LOW;                // 220504 acp
int pirState12 = LOW;

// ++++ Input status variable valXX A5 - 12, 13
int valA5 = 0;                    // variable for reading the pin status
int valA4 = 0;
int valA3 = 0;
int valA2 = 0;
int valA1 = 0;
int valA0 = 0;
int val11 = 0;                    // 220504 acp
int val12 = 0;

 // the setup function runs once when you press reset or power the board
void setup() {

// +++++ declare ledPinXX numbers as OUTPUT ++++ 
  pinMode(ledPin1, OUTPUT);       // declare LED4 as output
  pinMode(ledPin2, OUTPUT);       // declare LED5 as output
  pinMode(ledPin3, OUTPUT);       // declare LED6 as output
  pinMode(ledPin4, OUTPUT);       // declare LED4 as output
  pinMode(ledPin5, OUTPUT);       // declare LED5 as output
  pinMode(ledPin6, OUTPUT);       // declare LED6 as output
  pinMode(ledPin7, OUTPUT);       // declare LED7 as output
  pinMode(ledPin9, OUTPUT);       // declare LED9 as output
  pinMode(ledPin10, OUTPUT);      // declare LED10 as output
 
// ++++ declare inputPinXX numbers as INPUT   ++++
    pinMode(inputPinA5, INPUT);     // declare sensorA5 as input
    pinMode(inputPinA4, INPUT);     // declare sensorA4 as input
    pinMode(inputPinA3, INPUT);     // declare sensorA3 as input
    pinMode(inputPinA2, INPUT);     // declare sensorA2 as input
    pinMode(inputPinA1, INPUT);     // declare sensorA1 as input
    pinMode(inputPinA0, INPUT);     // declare sensorA0 as input
    pinMode(inputPin11, INPUT);     // declare sensor11 as input   220504 acp
    pinMode(inputPin12, INPUT);     // declare sensor12 as input
 
}

 // the loop function runs continuously 
void loop(){
  //Connect PIR inputPinA5 to '+LED1-' 
  valA5 = digitalRead(inputPinA5);  // read input value
  if (valA5 == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin1, HIGH);  // turn LED ON
  } else {
    digitalWrite(ledPin1, LOW); // turn LED OFF
    if (pirStateA5 == HIGH){
     pirStateA5 = LOW;
    }
  }

  //Connect PIR inputPinA4 to '+LED2-' 
  valA4 = digitalRead(inputPinA4);  // read input value
  if (valA4 == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin2, HIGH);  // turn LED ON
  } else {
    digitalWrite(ledPin2, LOW); // turn LED OFF
    if (pirStateA4 == HIGH){
     pirStateA4 = LOW;
    }
  }
  
    //Connect PIR inputPinA3 to '+LED3-' 
    valA3 = digitalRead(inputPinA3);  // read input value
    if (valA3 == HIGH) {            // check if the input is HIGH
      digitalWrite(ledPin3, HIGH);  // turn LED ON
    } else {
      digitalWrite(ledPin3, LOW); // turn LED OFF
      if (pirStateA3 == HIGH){
       pirStateA5 = LOW;
      }
  }
    //Connect PIR inputPinA2 to '+LED4-' 
    valA2 = digitalRead(inputPinA2);  // read input value
    if (valA2 == HIGH) {            // check if the input is HIGH
      digitalWrite(ledPin4, HIGH);  // turn LED ON
    } else {
      digitalWrite(ledPin4, LOW); // turn LED OFF
      if (pirStateA2 == HIGH){
       pirStateA2 = LOW;
      }
  }
    //Connect PIR inputPinA1 to '+LED5-' 
    valA1 = digitalRead(inputPinA1);  // read input value
    if (valA1 == HIGH) {            // check if the input is HIGH
      digitalWrite(ledPin5, HIGH);  // turn LED ON
    } else {
      digitalWrite(ledPin5, LOW); // turn LED OFF
      if (pirStateA1 == HIGH){
       pirStateA1 = LOW;
      }
  }
    //Connect PIR inputPinA0 to '+LED6-' 
    valA0 = digitalRead(inputPinA0);  // read input value
    if (valA0 == HIGH) {            // check if the input is HIGH
      digitalWrite(ledPin6, HIGH);  // turn LED ON
    } else {
      digitalWrite(ledPin6, LOW); // turn LED OFF
      if (pirStateA0 == HIGH){
       pirStateA0 = LOW;
      }
  }
    //Connect PIR inputPin12 to '+LED7-' 
    val12 = digitalRead(inputPin12);  // read input value
    if (val12 == HIGH) {            // check if the input is HIGH
      digitalWrite(ledPin7, HIGH);  // turn LED ON
    } else {
      digitalWrite(ledPin7, LOW); // turn LED OFF
      if (pirState12== HIGH){
       pirState12 = LOW;
      }
  }
  
 // the pin for LED marked 'D1'   green on PCB
    digitalWrite(ledPin10, HIGH); 
     delay(500);
  digitalWrite(ledPin10, LOW); 

       delay(500);
       
  // the pin for LED marked 'D2'   red on PCB
     digitalWrite(ledPin9, HIGH); 
      delay(500);
   digitalWrite(ledPin9, LOW); 
       delay(500);
       
 
}

code descending posted in code tags

/***********************************************************************************
*  Staircase_PIR_7_Descending.ino based on
Staircase_PIR_7_Ascending_220812.ino 
************************************************************************************/
// ++++  LED pin numbers ledPinX Output 2-10 ++++
int ledPin1 = 2;
int ledPin2 = 3;
int ledPin3 = 4;
int ledPin4 = 5;
int ledPin5 = 6;
int ledPin6 = 7;
int ledPin7 = 8;
int ledPin9 = 9;   // green  D2
int ledPin10 = 10;  // red  D1

// ++++ Input pin numbers for PIR inputPinXX A5-A0, 11, 12 13 ++++
int inputPinA5 = A5;               // choose the input pin (for PIR sensor)
int inputPinA4 = A4; 
int inputPinA3 = A3; 
int inputPinA2 = A2; 
int inputPinA1 = A1;
int inputPinA0 = A0;
int inputPin11 = 11;                // 220504 acp
int inputPin12 = 12;
// int inputPin13 = 13;

// ++++ PIR State pirStateXX = LOW ++++
int pirStateA5 = LOW;             // start, assuming no motion detected
int pirStateA4 = LOW;
int pirStateA3 = LOW;
int pirStateA2 = LOW; 
int pirStateA1 = LOW;
int pirStateA0 = LOW;
int pirState11 = LOW;                // 220504 acp
int pirState12 = LOW;

// ++++ Input status variable valXX A5 - 12, 13
int valA5 = 0;                    // variable for reading the pin status
int valA4 = 0;
int valA3 = 0;
int valA2 = 0;
int valA1 = 0;
int valA0 = 0;
int val11 = 0;                    // 220504 acp
int val12 = 0;

 // the setup function runs once when you press reset or power the board
void setup() {

// +++++ declare ledPinXX numbers as OUTPUT ++++ 
  pinMode(ledPin1, OUTPUT);       // declare LED4 as output
  pinMode(ledPin2, OUTPUT);       // declare LED5 as output
  pinMode(ledPin3, OUTPUT);       // declare LED6 as output
  pinMode(ledPin4, OUTPUT);       // declare LED4 as output
  pinMode(ledPin5, OUTPUT);       // declare LED5 as output
  pinMode(ledPin6, OUTPUT);       // declare LED6 as output
  pinMode(ledPin7, OUTPUT);       // declare LED7 as output
  pinMode(ledPin9, OUTPUT);       // declare LED9 as output
  pinMode(ledPin10, OUTPUT);      // declare LED10 as output
 
// ++++ declare inputPinXX numbers as INPUT   ++++
//  pinMode(inputPinA5, INPUT);     // declare sensorA5 as input
    pinMode(inputPinA4, INPUT);     // declare sensorA4 as input
    pinMode(inputPinA3, INPUT);     // declare sensorA3 as input
    pinMode(inputPinA2, INPUT);     // declare sensorA2 as input
    pinMode(inputPinA1, INPUT);     // declare sensorA1 as input
    pinMode(inputPinA0, INPUT);     // declare sensorA0 as input
    pinMode(inputPin11, INPUT);     // declare sensor11 as input   220504 acp
    pinMode(inputPin12, INPUT);     // declare sensor12 as input
 
}

 // the loop function runs continuously 
void loop(){
  //Connect PIR inputPinA4 to '+LED1-' 
  valA4 = digitalRead(inputPinA4);  // read input value
  if (valA4 == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin1, HIGH);  // turn LED ON
  } else {
    digitalWrite(ledPin1, LOW); // turn LED OFF
    if (pirStateA4 == HIGH){
     pirStateA4 = LOW;
    }
  }

  //Connect PIR inputPinA3 to '+LED2-' 
  valA3 = digitalRead(inputPinA3);  // read input value
  if (valA3 == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin2, HIGH);  // turn LED ON
  } else {
    digitalWrite(ledPin2, LOW); // turn LED OFF
    if (pirStateA3 == HIGH){
     pirStateA3 = LOW;
    }
  }
  
    //Connect PIR inputPinA2 to '+LED3-' 
    valA2 = digitalRead(inputPinA2);  // read input value
    if (valA2 == HIGH) {            // check if the input is HIGH
      digitalWrite(ledPin3, HIGH);  // turn LED ON
    } else {
      digitalWrite(ledPin3, LOW); // turn LED OFF
      if (pirStateA2 == HIGH){
       pirStateA2 = LOW;
      }
  }
    //Connect PIR inputPinA1 to '+LED4-' 
    valA1 = digitalRead(inputPinA1);  // read input value
    if (valA1 == HIGH) {            // check if the input is HIGH
      digitalWrite(ledPin4, HIGH);  // turn LED ON
    } else {
      digitalWrite(ledPin4, LOW); // turn LED OFF
      if (pirStateA1 == HIGH){
       pirStateA1 = LOW;
      }
  }
    //Connect PIR inputPinA0 to '+LED5-' 
    valA0 = digitalRead(inputPinA0);  // read input value
    if (valA0 == HIGH) {            // check if the input is HIGH
      digitalWrite(ledPin5, HIGH);  // turn LED ON
    } else {
      digitalWrite(ledPin5, LOW); // turn LED OFF
      if (pirStateA0 == HIGH){
       pirStateA0 = LOW;
      }
  }
    //Connect PIR inputPin12 to '+LED6-' 
    val12 = digitalRead(inputPin12);  // read input value
    if (val12 == HIGH) {            // check if the input is HIGH
      digitalWrite(ledPin6, HIGH);  // turn LED ON
    } else {
      digitalWrite(ledPin6, LOW); // turn LED OFF
      if (pirState12 == HIGH){
       pirState12 = LOW;
      }
  }
    //Connect PIR inputPin11 to '+LED7-' 
    val11 = digitalRead(inputPin11);  // read input value
    if (val11 == HIGH) {            // check if the input is HIGH
      digitalWrite(ledPin7, HIGH);  // turn LED ON
    } else {
      digitalWrite(ledPin7, LOW); // turn LED OFF
      if (pirState11== HIGH){
       pirState11 = LOW;
      }
  }
  
 // the pin for LED marked 'D1'   green on PCB
    digitalWrite(ledPin10, HIGH); 
     delay(500);
  digitalWrite(ledPin10, LOW); 

       delay(500);
       
  // the pin for LED marked 'D2'   red on PCB
     digitalWrite(ledPin9, HIGH); 
      delay(500);
   digitalWrite(ledPin9, LOW); 
       delay(500);
       
 
}

code directionality posted in code tags

/***********************************************************************************
*  Staircase 7 PIR w D1 & D2 Sketch
* to test PCB Staircase 220308 Beta
* Based on Staircase_Blink_7_w_D1_D2_220810
* with parts based on 
* Staircase_7_Channel_w_heartbeat_and_D1_D2_220428
* and
* Staircase_7_Channel_w_heartbeat_and_D1_D2_220528_desc
* Revised and name updated to ....220815: changed variable
* names and put D1 blinker in Ascending section amd 
* D2 blinker in Descending section
************************************************************************************/
// ++++  LED pin numbers ledPinX Output 2-10 ++++
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int LED6 = 7;
int LED7 = 8;
int LEDD1 = 9;   // red D1
int LEDD2 = 10;  // green  D2

// ++++ Input pin numbers for PIR inputPinXX A5-A0, 11, 12 13 ++++
int PIR1 = A5;               // choose the input pin (for PIR sensor)
int PIR2 = A4; 
int PIR3 = A3; 
int PIR4 = A2; 
int PIR5 = A1;
int PIR6 = A0;
int PIR7 = 11;                // 220504 acp
int PIR8 = 12;
// int inputPin13 = 13;

// ++++ PIR State pirStateXX = LOW ++++
int pirState1 = LOW;             // start, assuming no motion detected
int pirState2 = LOW;
int pirState3 = LOW;
int pirState4 = LOW; 
int pirState5 = LOW;
int pirState6 = LOW;
int pirState7 = LOW;                // 220504 acp
int pirState8 = LOW;

// ++++ Input status variable valXX A5 - 12, 13
int val1 = 0;                    // variable for reading the pin status
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;
int val6 = 0;
int val7 = 0;                    // 220504 acp
int val8 = 0;

 // the setup function runs once when you press reset or power the board
void setup() {

// +++++ declare ledPinXX numbers as OUTPUT ++++ 
  pinMode(LED1, OUTPUT);       // declare LED4 as output
  pinMode(LED2, OUTPUT);       // declare LED5 as output
  pinMode(LED3, OUTPUT);       // declare LED6 as output
  pinMode(LED4, OUTPUT);       // declare LED4 as output
  pinMode(LED5, OUTPUT);       // declare LED5 as output
  pinMode(LED6, OUTPUT);       // declare LED6 as output
  pinMode(LED7, OUTPUT);       // declare LED7 as output
  pinMode(LEDD1, OUTPUT);       // declare LED9 as output
  pinMode(LEDD2, OUTPUT);      // declare LED10 as output
 
// ++++ declare PIRXX numbers as INPUT   ++++
    pinMode(PIR1, INPUT);     // declare sensorA5 as input
    pinMode(PIR2, INPUT);     // declare sensorA4 as input
    pinMode(PIR3, INPUT);     // declare sensorA3 as input
    pinMode(PIR4, INPUT);     // declare sensorA2 as input
    pinMode(PIR5, INPUT);     // declare sensorA1 as input
    pinMode(PIR6, INPUT);     // declare sensorA0 as input
    pinMode(PIR7, INPUT);     // declare sensor11 as input   220504 acp
    pinMode(PIR8, INPUT);     // declare sensor12 as input
 
}

 // the loop function runs continuously 
void loop(){
// if statement to determine if walker comeing from top or bottom of staircase
  val1 = digitalRead(PIR1);  // read input value from PIR at bottom
  if (val1 == HIGH) {
  //Connect PIR1 to '+LED1-' 
  val1 = digitalRead(PIR1);  // read input value
  if (val1 == HIGH) {            // check if the input is HIGH
    val1 = digitalRead(PIR1);  // read input value
    digitalWrite(LED1, HIGH);  // turn LED ON
  } else {
    digitalWrite(LED1, LOW); // turn LED OFF
    if (pirState1 == HIGH){
     pirState1 = LOW;
    }
  }

  //Connect PIR2 to '+LED2-' 
  val2 = digitalRead(PIR2);  // read input value
  if (val2 == HIGH) {            // check if the input is HIGH
    digitalWrite(LED2, HIGH);  // turn LED ON
  } else {
    digitalWrite(LED2, LOW); // turn LED OFF
    if (pirState2 == HIGH){
     pirState2 = LOW;
    }
  }
  
    //Connect PIR3 to '+LED3-' 
    val3 = digitalRead(PIR3);  // read input value
    if (val3 == HIGH) {            // check if the input is HIGH
      digitalWrite(LED3, HIGH);  // turn LED ON
    } else {
      digitalWrite(LED3, LOW); // turn LED OFF
      if (pirState3 == HIGH){
       pirState3 = LOW;
      }
  }
    //Connect PIR4 to '+LED4-' 
    val4 = digitalRead(PIR4);  // read input value
    if (val4 == HIGH) {            // check if the input is HIGH
      digitalWrite(LED4, HIGH);  // turn LED ON
    } else {
      digitalWrite(LED4, LOW); // turn LED OFF
      if (pirState4 == HIGH){
       pirState4 = LOW;
      }
  }
    //Connect PIR5 to '+LED5-' 
    val5 = digitalRead(PIR5);  // read input value
    if (val5 == HIGH) {            // check if the input is HIGH
      digitalWrite(LED5, HIGH);  // turn LED ON
    } else {
      digitalWrite(LED5, LOW); // turn LED OFF
      if (pirState5 == HIGH){
       pirState5 = LOW;
      }
  }
    //Connect PIR6 to '+LED6-' 
    val6 = digitalRead(PIR6);  // read input value
    if (val6 == HIGH) {            // check if the input is HIGH
      digitalWrite(LED6, HIGH);  // turn LED ON
    } else {
      digitalWrite(LED6, LOW); // turn LED OFF
      if (pirState6 == HIGH){
       pirState6 = LOW;
      }
  }
    //Connect PIR7 to '+LED7-' 
    val7 = digitalRead(PIR7);  // read input value
    if (val7 == HIGH) {            // check if the input is HIGH
      digitalWrite(LED7, HIGH);  // turn LED ON
    } else {
      digitalWrite(LED7, LOW); // turn LED OFF
      if (pirState7 == HIGH){
       pirState7 = LOW;
      }
  }
{
}
}
  else {
  // This is the Descending use case  
  //Connect PIR2 to '+LED1-' 
    val2 = digitalRead(PIR2);  // read input value
    if (val2 == HIGH) {            // check if the input is HIGH
      digitalWrite(LED1, HIGH);  // turn LED ON
    } else {
      digitalWrite(LED1, LOW); // turn LED OFF
      if (pirState2 == HIGH){
       pirState2 = LOW;
      }
    }
  
    //Connect PIR3 to '+LED2-' 
    val3 = digitalRead(PIR3);  // read input value
    if (val3 == HIGH) {            // check if the input is HIGH
      digitalWrite(LED2, HIGH);  // turn LED ON
    } else {
      digitalWrite(LED2, LOW); // turn LED OFF
      if (pirState3 == HIGH){
       pirState3 = LOW;
      }
    }
    
      //Connect PIR4 to '+LED3-' 
      val4 = digitalRead(PIR4);  // read input value
      if (val4 == HIGH) {            // check if the input is HIGH
        digitalWrite(LED3, HIGH);  // turn LED ON
      } else {
        digitalWrite(LED3, LOW); // turn LED OFF
        if (pirState4 == HIGH){
         pirState4 = LOW;
        }
    }
      //Connect PIR5 to '+LED4-' 
      val5 = digitalRead(PIR5);  // read input value
      if (val5 == HIGH) {            // check if the input is HIGH
        digitalWrite(LED4, HIGH);  // turn LED ON
      } else {
        digitalWrite(LED4, LOW); // turn LED OFF
        if (pirState5 == HIGH){
         pirState5 = LOW;
        }
    }
      //Connect PIR6 to '+LED5-' 
      val6 = digitalRead(PIR6);  // read input value
      if (val6 == HIGH) {            // check if the input is HIGH
        digitalWrite(LED5, HIGH);  // turn LED ON
      } else {
        digitalWrite(LED5, LOW); // turn LED OFF
        if (pirState6 == HIGH){
         pirState6 = LOW;
        }
    }
      //Connect PIR7 to '+LED6-' 
      val7 = digitalRead(PIR7);  // read input value
      if (val7 == HIGH) {            // check if the input is HIGH
        digitalWrite(LED6, HIGH);  // turn LED ON
      } else {
        digitalWrite(LED6, LOW); // turn LED OFF
        if (pirState7 == HIGH){
         pirState7 = LOW;
        }
    }
      //Connect PIR8 to '+LED7-' 
      val8 = digitalRead(PIR8);  // read input value
      if (val8 == HIGH) {            // check if the input is HIGH
        digitalWrite(LED7, HIGH);  // turn LED ON
      } else {
        digitalWrite(LED7, LOW); // turn LED OFF
        if (pirState8 == HIGH){
         pirState8 = LOW;
        }
  }
  }
  
  
 // the pin for LED marked 'D1'   red on PCB
    digitalWrite(LEDD1, HIGH); 
     delay(500);
  digitalWrite(LEDD1, LOW); 

       delay(500);
       
  // the pin for LED marked 'D2'   green on PCB
     digitalWrite(LEDD2, HIGH); 
      delay(500);
   digitalWrite(LED2, LOW); 
       delay(500);
       
 
}

I'd put a sensor at the top and the bottom of the staircase to detect staircase use. If the Top of stair case light comes on then illuminate the top of stair case light until bottom of stair case light comes on. Then all light off till next event.

BTW, you did read about how to use code tags. Why not use them?

Better yet use something like ESP32's with WiFi and have the ESP32 at the top of the stairs, via WiFI, tell the ESP32 at the bottom of the stairs someone is coming turn on the lights spin up the band and do a little dance.

At first glance it looks like you’re overthinking the problem.
First thing I’d do is reorganise your inputs and outputs into logical structs and arrays.

I doubt there’s different code needed for ascending and descending, because you know which step is triggered first… in fact, you could have two or more people simultaneously, starting from the top, and from the bottom - passing in the middle.

Look at the problem a bit longer, and break it down. The Arduino can do a lot more than you can think.

It looks like you don't know how the loop() works.

In both the ascending and descending loops you have shared, all the if statements get executed every time through the loop.

It makes no difference if you check them top to bottom, bottom to top, or make a decision (which gets remade every time you loop) as to the order in which you check the PIRs.

You need to rethink this from the top down. Or the bottom up. <- See what I did there?

Start by seeing if the PIRs on each step trigger only if that step is entered. In my experience you are asking too much of the PIRs.

A pressure pad on the step,or a light beam might give more reliable reports of enter/occupancy.

If you have reliable step sensing, there is no need for anything other than lighting a step while PIR has triggered. Perhaps a PIR trigger would lead to a brief stab of light on the corresponding step, of time about right for the time it would be occupied by a normal person moving in the stairs.

What if there is more than one person on the steps? As mentioned, this would fit the above simple idea: briefly light a stair that has reported activity.

Detecting direction is just watching for a trigger that is above or below a previously recently triggered step.

a7

Have you considered something simpler, like turning on the two nearest LEDS as long as a sensor is triggered, perhaps adding a timeout?

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