Arduino stair led light using 10 ledS 2 tactile switches

I have tested simple concept stair LED light. project contains, Arduino Nano, 10X1W LEDs, 2 Tactile switches.  Arduino code can be downloaded using link, its modified code  from original code.  I have tested this project  with 10 LEDs, number of LEDs can be increase as per requirment and available pins on arduino, Arduino Mega provides liberty to use many pins or using 74HC595 serial to parrelel converter can help to use tons of LEDs.


Arduino Pins Configurations (LED>Arduino Pins)

  • LED1>D3, LED2>D4, LED3>D5, LED4>D6, LED5>D7, LED6>D8, LED7>D9, LED8>D10, LED9>D11, LED10>D12
  • Tactile Switch 1 > A0, Tactile Switch 2> A1
  • Switches Needs Pull-Up Resistor of 10K Ohms

Arduino Code

/*
LED stair lights
*/

//LED pin assignments
int led1 = 3;
int led2 = 4;
int led3 = 5;
int led4 = 6;
int led5 = 7;
int led6 = 8;
int led7 = 9;
int led8 = 10;
int led9 = 11;
int led10 = 12;

// button pin assignments
int b_up = A0; //button at bottom of stairs
int b_down = A1; //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);
pinMode(led10, 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);
delay(tOn);
digitalWrite(led10, 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);
delay(tOff);
digitalWrite(led10, 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(led10, HIGH);
delay(tOn);
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(led10, LOW);
delay(tOff);
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