Hey All,
New to posting here in the community.
I originally got an Arduino Uno years ago, to do a stairs lighting project, but ended up doing many others before actually getting around to doing the stairs project.
I'm finally doing it and ran into an issue with the coding and wanted to see if someone could give some pointers.
I'm doing the typical stairs lighting project where there's a sensor at the bottom and top of the stairs that triggers LED strips (solid white, not RGB or anything fancy) and illuminates step by step (up or down) depending on which sensor is triggered. I'm doing my programming in stages, to make sure things work as I add functions, so right now I'm doing the step by step illumination, then shut all off at once after 10sec.
I'm using HC-SR501 PIR sensors (at the moment) and the issue I have is... When the sensor is triggered, the strips light one by one in the correct direction, stay on for 10sec, then go off, but it then runs the opposite direction once.
Each sensor triggers the correct direction, but then does the one cycle in the opposite direction . I'm sure there's some sort of "stop" command that I need, but all of my past projects were just continuous run loops for special stage lighting props, I never had a "stop", therefore I'm looking for some assistance on this one and any help would be appreciated.
The forums won't let me post an attachment, so I'm posting the code below - sorry so long!!
/*******************************************
TITLE: Stairway Lighting - Chase
*********************************************/
int sensorPin1 = A4; //Bottom - Up sensor
int sensorPin2 = A5; //Top - Down sensor
int sensorStatus1 = 0;
int sensorStatus2 = 0;
int ledPin2 = 2; // The outputlight
int ledPin3 = 3; // The outputlight
int ledPin4 = 4; // The outputlight
int ledPin5 = 5; // The outputlight
int ledPin6 = 6; // The outputlight
int ledPin7 = 7; // The outputlight
int ledPin8 = 8; // The outputlight
int ledPin9 = 9; // The outputlight
int ledPin10 = 10; // The outputlight
int ledPin11 = 11; // The outputlight
int ledPin12 = 12; // The outputlight
int ledPin13 = 13; // The outputlight
void setup() {
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(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
}
void loop() {
sensorStatus1 = digitalRead(A4); //Stairs Bottom Sensor - Motion Up
if (sensorStatus1 == HIGH || sensorStatus2 == HIGH) {
// if bottom sensor is triggered lights travel upward
digitalWrite(13, HIGH);
delay(200);
digitalWrite(12, HIGH);
delay(200);
digitalWrite(11, HIGH);
delay(200);
digitalWrite(10, HIGH);
delay(200);
digitalWrite(9, HIGH);
delay(200);
digitalWrite(8, HIGH);
delay(200);
digitalWrite(7, HIGH);
delay(200);
digitalWrite(6, HIGH);
delay(200);
digitalWrite(5, HIGH);
delay(200);
digitalWrite(4, HIGH);
delay(200);
digitalWrite(3, HIGH);
delay(200);
digitalWrite(2, HIGH);
delay(10000);// delay time 10 sec
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
}
sensorStatus2 = digitalRead(A5); //Stairs Top Sensor - Motion Down
if (sensorStatus2 == HIGH || sensorStatus1 == HIGH) {
// if top sensor is triggered lights travel downward
digitalWrite(2, HIGH);
delay(200);
digitalWrite(3, HIGH);
delay(200);
digitalWrite(4, HIGH);
delay(200);
digitalWrite(5, HIGH);
delay(200);
digitalWrite(6, HIGH);
delay(200);
digitalWrite(7, HIGH);
delay(200);
digitalWrite(8, HIGH);
delay(200);
digitalWrite(9, HIGH);
delay(200);
digitalWrite(10, HIGH);
delay(200);
digitalWrite(11, HIGH);
delay(200);
digitalWrite(12, HIGH);
delay(200);
digitalWrite(13, HIGH);
delay(10000);// delay time 10 sec
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
}
}