Stair lighting system - Having issues with the code

Hi,

I am having some issues with my code,

Thing is, it does what it has to do but not what I expected... I'm a beginner trying things out.

Issue: When i activate sensor one (PIR) it takes the entire cycle of lights lighting up and then turning off until another sensor can re-trigger the light going up or down...

Here is my code part of which is what is on here.

int calibrationTime = 30;
//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 ledPin1 = 22;
int ledPin2 = 24;
int ledPin3 = 26;
int ledPin4 = 28;
int ledPin5 = 30;
int ledPin6 = 32;
int ledPin7 = 34;
int ledPin8 = 36;
int ledPin9 = 38;
int ledPin10 = 40;
int ledPin11 = 42;
int ledPin12 = 44;
int ledPin13 = 46;
int ledPin14 = 48;


int pirPin1 = 50;
int pirPin2 = 52;

void setup() {
  Serial.begin(9600);
  Serial.print("calibrating sensors ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);

  pinMode(pirPin1, INPUT);
  pinMode(pirPin2, INPUT);
  
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);
  pinMode(ledPin9, OUTPUT);
  pinMode(ledPin10, OUTPUT);
  pinMode(ledPin11, OUTPUT);
  pinMode(ledPin12, OUTPUT);
  pinMode(ledPin13, OUTPUT);
  pinMode(ledPin14, OUTPUT);

digitalWrite(pirPin1, LOW);
digitalWrite(pirPin2, LOW);
}
void loop(){
  
if(digitalRead(pirPin1) == HIGH){
digitalWrite(ledPin1, HIGH);
delay (500);
digitalWrite(ledPin2, HIGH);
delay (500);
digitalWrite(ledPin3, HIGH);
delay (500);
digitalWrite(ledPin4, HIGH);
delay (500);
digitalWrite(ledPin5, HIGH);
delay (500);
digitalWrite(ledPin6, HIGH);
delay (500);
digitalWrite(ledPin7, HIGH);
delay (500);
digitalWrite(ledPin8, HIGH);
delay (500);
digitalWrite(ledPin9, HIGH);
delay (500);
digitalWrite(ledPin10, HIGH);
delay (500);
digitalWrite(ledPin11, HIGH);
delay (500);
digitalWrite(ledPin12, HIGH);
delay (500);
digitalWrite(ledPin13, HIGH);
delay (500);
digitalWrite(ledPin14, HIGH);
delay (500);
}
if(digitalRead(pirPin1) == LOW){
digitalWrite(ledPin1, LOW);
delay (500);
digitalWrite(ledPin2, LOW);
delay (500);
digitalWrite(ledPin3, LOW);
delay (500);
digitalWrite(ledPin4, LOW);
delay (500);
digitalWrite(ledPin5, LOW);
delay (500);
digitalWrite(ledPin6, LOW);
delay (500);
digitalWrite(ledPin7, LOW);
delay (500);
digitalWrite(ledPin8, LOW);
delay (500);
digitalWrite(ledPin9, LOW);
delay (500);
digitalWrite(ledPin10, LOW);
delay (500);
digitalWrite(ledPin11, LOW);
delay (500);
digitalWrite(ledPin12, LOW);
delay (500);
digitalWrite(ledPin13, LOW);
delay (500);
digitalWrite(ledPin14, LOW);
delay (500);
}}

I don't really have an option here but to take the lights activating in another loop.

If anybody would have an idea here would be nice to look at it.

chris442:
Issue: When i activate sensor one (PIR) it takes the entire cycle of lights lighting up and then turning off until another sensor can re-trigger the light going up or down...

Once a sequence is started you're not checking any inputs for seven seconds. This happens because when a delay() starts the processor does nothing else until it's done.

Get a grasp of the essentials by getting to know the first five demos in IDE -> file/examples/digital.

Then look at Several things at the same time.

chris442:
it does what it has to do but not what I expected

Say what it's supposed to do.

What I want is my lights to go on as I walk onto the first step. Either going up or coming down, and to light up one after the other in the direction I am going.

I have that going so far... but if there are two people let say, one coming down, the other going up one shortly after the other, the lights won't go on on both sides. It will go thru it's cycle and I understand that much.

Have you followed up on any of the reading suggested in reply #1?

Yes, I am still on it. been trying to mess around with a few things, I can now have 4 leds to blink one after the other but that is not really what I need.

found a code for fading... quite interesting principal for my system

Q what are we doing right now?
A Nothing. all the leds are off.
Q Massive! Is the PIR active?
A no
Action: meh, nothing to do

Q what are we doing right now?
A Nothing. all the leds are off.
Q Massive! Is the PIR active?
A Yes
Action: Woah! Light LED 0. We are now 'lighting up LEDs'. The next LED we need to light os LED 1. We need to light it half a second from now().

Q what are we doing right now?
A lighting up the leds
Q cool. is the pir still active?
A yup.
Q what's the next led we have to light up?
A led 7
Q how long has elapsed since we lit up led 6?
A quarter of a second
Action: ok, we don't need to do anything.

// some time passes

Q what are we doing right now?
A lighting up the leds
Q cool. is the pir still active?
A yup.
Q what's the next led we have to light up?
A led 7
Q how long has elapsed since we lit up led 6?
A half a second
Action: woah! ok. light up led 7. the next led we need to light up is led 8. we need to do this half a second from now().

// some time passes

Q what are we doing right now?
A lighting up the leds
Q cool. is the pir still active?
A nope
Q Yikes, what's the next led we have to light up?
A led 8
Action: ok. extinguish led 7. we are now unighting some leds. the next led we need to unlight led 6. we need to do this half a second from now().

// some time passes

Q what are we doing right now?
A unlighting the leds
Q cool. is the pir still inactive?
A Yup.
Q ok, what is the next LED we have to unlight?
A led 0
Q How long since we unlit LED 1?
A half a second
Action: ok. extinguish led 0. We are now idling with the leds all off. No need to keep track of time.

Ok,

I know it follows one step after the other... is there a way I can have 2 loops?

Hi chris,

you can have 10.000 loops if you want. There are two basic ways to make your project work.
One way it will take months until you are finished. The other way it will take you 10-20 hours so 4 to 10 days depending on how much time you want to spend per day.

way1: ask a small question waiting for somebody to answer your small question learn just a tiny little bit of programming through this answer

way2: working through a programming-tutorial that you have proven to be easy to understand for you.
If you don't understand it move on to the next tutorial. Testing the second one

Working through a tutorial does not tell thevery next step for your project. It explains basic concepts.
Once you have understood the basic concepts it will speed-up your own code-writing a lot.

I redommend Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

There is an additional effect. If other users see that you walk up the learning-curve through your own effort much more people will be willing to answer your questions.

best regards Stefan