Working With 2 Pir sensors with single arduino uno.

hi

building automatic stair case lighting using using

arduino uno

x2 pir sensors (one for upwards and another for downwards )

4 relays to power-up step by step led strip . (because i am using normal rgb led strips that is non-programmable)

and power adapters …

.
I searched and found that with single arduino uno can run 2 pir sensors …

https://cdn.instructables.com/ORIG/F8T/0II8/ILCN9NJ9/F8T0II8ILCN9NJ9.ino

My problem is when person cross down stairs pir sensor detects and run the cycle but when a person reach up stairs and cross to up pir sensor it also detects and put it on queue after completion of down stairs loop . arduino runs the queue process and starts automatically up to down stairs process …

i want to put if any one sensor detects another should be in hold even person cross it so one program completes its task … after that it reset to sensing …

CODE :

unsigned long timeOut=6000; // timestamp to remember when the PIR was triggered.
int ledPin = 13; // choose the pin for the LED
int downUp = 0; // variable to rememer the direction of travel up or down the stairs
int alarmPinTop = 4; // PIR at the top of the stairs
int alarmPinBottom = 3; // PIR at the bottom of the stairs
int alarmValueTop = LOW; // Variable to hold the PIR status
int alarmValueBottom = LOW; // Variable to hold the PIR status
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
#define RELAY1 9
#define RELAY2 10
#define RELAY3 11
#define RELAY4 12

void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(RELAY1, OUTPUT); // declare relay1 as output
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
pinMode(alarmPinTop, INPUT_PULLUP); // for PIR at top of stairs initialise the input pin and use the internal restistor
pinMode(alarmPinBottom, INPUT_PULLUP); // for PIR at bottom of stairs initialise the input pin and use the internal restistor
delay (200); // it takes the sensor 2 seconds to scan the area around it before it can
//detect infrared presence.

}

void loop(){

alarmValueTop = digitalRead(alarmPinTop); // Constantly poll the PIR at the top of the stairs
Serial.println(alarmPinTop);
alarmValueBottom = digitalRead(alarmPinBottom); // Constantly poll the PIR at the bottom of the stairs
Serial.println(alarmPinBottom);

if (alarmValueTop == HIGH && downUp != 2) { // the 2nd term allows timeOut to be contantly reset if one lingers at the top of the stairs before decending but will not allow the bottom PIR to reset timeOut as you decend past it.
timeOut = millis(); // Timestamp when the PIR is triggered. The LED cycle wil then start.
downUp = 1;
Serial.println(“downup=1”);
//clearStrip();
topdown(); // lights up the strip from top down
}

if (alarmValueBottom == HIGH && downUp != 1) { // the 2nd term allows timeOut to be contantly reset if one lingers at the bottom of the stairs before decending but will not allow the top PIR to reset timeOut as you decend past it.
timeOut = millis(); // Timestamp when the PIR is triggered. The LED cycle wil then start.
downUp = 2;
Serial.println(“downup=2”);
//clearStrip();
bottomup(); // lights up the strip from bottom up
}
}

void topdown() {
Serial.println (“detected top”); // Helpful debug message

//for(int i=0; i<3; i++) { // Helpful debug indication flashes led on Arduino board twice
digitalWrite(ledPin,HIGH);
delay(5000);
digitalWrite(ledPin,LOW);
digitalWrite(RELAY1,HIGH);
delay(1500);
digitalWrite(RELAY2,HIGH);
delay(1500);
digitalWrite(RELAY3,HIGH);
delay(1500);
digitalWrite(RELAY4,HIGH);
delay(4000);

//delay(2000);
Serial.println(“delay 2500”);
//downUp = 0;
if (alarmValueBottom == HIGH ) {
delay (1000);
Serial.println(“top to botton cycle started”);
digitalWrite(RELAY4,LOW);
delay(2000);
digitalWrite(RELAY3,LOW);
delay(2000);
digitalWrite(RELAY2,LOW);
delay(2000);
digitalWrite(RELAY1,LOW);
}
else{
delay (10);
downUp = 0;
digitalWrite(RELAY1,LOW);
digitalWrite(RELAY2,LOW);
digitalWrite(RELAY3,LOW);
digitalWrite(RELAY4,LOW);}
downUp = 0;
//alarmValueBottom = LOW;
//alarmValueTop = LOW;
//}

}

void bottomup() {
Serial.println (“detected bottom”); // Helpful debug message
//for(int i=0; i<3; i++) { // Helpful debug indication flashes led on Arduino board twice
digitalWrite(ledPin,HIGH);
delay(8000);
digitalWrite(ledPin,LOW);
delay(500);

downUp = 0;
//}

}