Enhancing Stair Safety with Arduino: Exploring Five Lighting Modes
Imagine a staircase that not only illuminates for safety but also offers various lighting modes to cater to different needs. The Arduino Stair Lights project does just that, using components like Arduino Nano, lasers, laser receivers, and a photoresistor. It ensures safer staircases while providing customizable lighting experiences.
How It Works:
- Initialization: When powered on, the Arduino gets ready and waits for signals from sensors.
- Detecting Movement: Lasers on one side of the staircase emit beams to the other side. If these beams are interrupted, indicating movement, the sensors pick up the change and notify the Arduino.
- Lighting Decision: The Arduino, considering the ambient light level sensed by the photoresistor, determines to switch on the device or not.
Exploring the Five Lighting Modes:
- Progressive Illumination: Each step lights up progressively as someone ascends or descends, offering a smooth and guiding effect.
- Individual Step Lighting: Lights under each step illuminate individually upon detection of movement, ensuring clear visibility and safety.
- Testing Mode: This mode is for testing purposes. All lights, lasers, and laser receivers are activated simultaneously to ensure they are functioning correctly.
- Step Lighting with Photoresistor: Similar to Mode 2, each step lights up individually upon movement. However, in this mode, the presence of a photoresistor enables the lasers, ensuring precise activation.
- Progressive Illumination with Photoresistor: Similar to Mode 1, lights illuminate progressively with movement. However, the presence of a photoresistor enables the lasers, ensuring accurate timing and activation.
Benefits of the Five Modes:
- Tailored Safety and Convenience: Users can choose the lighting mode that best suits their preferences and needs, ensuring optimal safety and convenience on the stairs.
- Versatility and Customization: Whether it’s a gradual glow or individual step lighting, the Arduino Stair Lights project offers customizable options to match various styles and preferences.
- Ease of Use and Installation: Despite its advanced features, the project remains user-friendly, allowing easy installation and customization for users of all skill levels.
Conclusion:
The Arduino Stair Lights project elevates stair safety and ambiance by offering a range of customizable lighting modes. From progressive illumination to individual step lighting, each mode caters to different preferences and needs. With the addition of testing and photoresistor-enabled modes, the project ensures accuracy and reliability in its functionality. So, whether you seek a gentle glow or precise step lighting, Arduino Stair Lights delivers safety and customization in every step.
Arduino nano
KY-008 3Pin 650nm Red Laser Transmitter
As much as the stairs
Laser Sensor Module non-modulator Tube Laser Receiver
As much as the receivers
USB LED
As much as the stairs
You can use any other source of light
Photoresistor Sensor Module
As much as the stairs
You can use any other source of light
Breadboard
5v Relay Module for Arduino
2x16 LCD with I2C Module
Tactile Push Button Switch Momentary
10K ohm Carbon Film Resistor
Lots of wires
3d printed LCD case
Link to 3d files https://www.thingiverse.com/thing:4693741
// setup lcd 16x2 #include <Wire.h> // Library for I2C communication #include <LiquidCrystal_I2C.h> // Library for LCD // Wiring: SDA pin is connected to A4 and SCL pin to A5. // Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered) LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); // Change to (0x3F,16,2) for 16x2 LCD. // setup for average photoresistor readings const int numReadings = 5; // number of Photorestistor Reading to calculate average int readings[numReadings]; // the readings from the analog input int readIndex = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average int PhotoResistorPin = A7; //The number of each led represents each stair from the bottom to the top the same logic applies to the the leds //All led Pins int led1 = 11; int led2 = A2; int led3 = A1; int led4 = A0; int led5 = 8; int led6 = 13; int led7 = 12; //All laserReceiver Pins int laserReceiver1 = 9; int laserReceiver2 = 2; int laserReceiver3 = 3; int laserReceiver4 = 4; int laserReceiver5 = 5; int laserReceiver6 = 6; int laserReceiver7 = 7; int laser = 10; // the pin number of the laser relay const int buttonPin = A3; // the number of the pushbutton pin int buttonState = 0; // variable for reading the pushbutton status int counterButton = 1; // variable for counting how many times the buttom is pressed //Associated with blinkMode int checkLights = 0; int ascending = 1; // variable for ascending (1) or descending (0) the stairs int checklight = 0; void setup() { Serial.begin(9600); // Initiate the LCD: lcd.init(); lcd.backlight(); // initialize all the photoresistor readings to 0: for (int thisReading = 0; thisReading < numReadings; thisReading++) { readings[thisReading] = 0; } //All laserReceiver Input pinMode(laserReceiver1, INPUT); pinMode(laserReceiver2, INPUT); pinMode(laserReceiver3, INPUT); pinMode(laserReceiver4, INPUT); pinMode(laserReceiver5, INPUT); pinMode(laserReceiver6, INPUT); pinMode(laserReceiver7, INPUT); pinMode(laser, OUTPUT); // relay output pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input: //All led Output pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(led5, OUTPUT); pinMode(led6, OUTPUT); pinMode(led7, OUTPUT); lcd.clear(); lcd.setCursor(0, 0); // Set the cursor on the first column and first row. lcd.print("Mode 1 No Sensor"); // Print the string "Hello World!" lcd.setCursor(0, 1); //Set the cursor on the third column and the second row (counting starts at 0!). lcd.print("Progressive Mode"); } void loop() { buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { Serial.print("high "); counterButton = counterButton + 1; if (counterButton ==6 ) { counterButton =1; } if (counterButton ==1 ) { lcd.clear(); lcd.setCursor(0, 0); // Set the cursor on the first column and first row. lcd.print("Mode 1 No Sensor"); lcd.setCursor(0, 1); //Set the cursor on the third column and the second row (counting starts at 0!). lcd.print("Progressive Mode"); } if (counterButton ==2 ) { lcd.clear(); lcd.setCursor(0, 0); // Set the cursor on the first column and first row. lcd.print("Mode 2 No Sensor"); // Print the string "Hello World!" lcd.setCursor(0, 1); //Set the cursor on the third column and the second row (counting starts at 0!). lcd.print("Step Mode"); } if (counterButton ==3 ) { lcd.clear(); lcd.setCursor(0, 0); // Set the cursor on the first column and first row. lcd.print("Mode 3 Check Serial"); // Print the string "Hello World!" lcd.setCursor(0, 1); //Set the cursor on the third column and the second row (counting starts at 0!). lcd.print("Test Mode"); } if (counterButton ==4 ) { lcd.clear(); lcd.setCursor(0, 0); // Set the cursor on the first column and first row. lcd.print("Mode 4 Sensor"); // Print the string "Hello World!" lcd.setCursor(0, 1); //Set the cursor on the third column and the second row (counting starts at 0!). lcd.print("Step Mode"); } if (counterButton ==5 ) { lcd.clear(); lcd.setCursor(0, 0); // Set the cursor on the first column and first row. lcd.print("Mode 5 Sensor"); // Print the string "Hello World!" lcd.setCursor(0, 1); //Set the cursor on the third column and the second row (counting starts at 0!). lcd.print("Progressive Mode"); } Serial.println(counterButton); delay (100); } switch (counterButton) { case 1: blinkMode(); break; case 2: NormalMode(); break; case 3: test(); break; case 4: PhotoresistorNormal(); break; case 5: PhotoresistorBlink(); break; } delay(50);//delay is for next time } void GetAverageLight(){ int value = analogRead(PhotoResistorPin); //////////////////////calculating average photoresistor readings////////// // subtract the last reading: total = total - readings[readIndex]; // read from the sensor: readings[readIndex] = analogRead(PhotoResistorPin); Serial.print("now reading "); Serial.print(readings[readIndex]); Serial.print(" array "); for(int i = 0; i < numReadings; i++) { Serial.print(readings[i]); Serial.print(" "); } // add the reading to the total: total = total + readings[readIndex]; // advance to the next position in the array: readIndex = readIndex + 1; // if we're at the end of the array... if (readIndex >= numReadings) { // ...wrap around to the beginning: readIndex = 0; } Serial.print(" total "); Serial.print(total); // calculate the average: average = total / numReadings; Serial.print(" average "); Serial.println(average); } void NormalMode() { //(Lights each led every time a stair has been activated) digitalWrite(laser, HIGH); int value1 = digitalRead(laserReceiver1); int value2 = digitalRead(laserReceiver2); int value3 = digitalRead(laserReceiver3); int value4 = digitalRead(laserReceiver4); int value5 = digitalRead(laserReceiver5); int value6 = digitalRead(laserReceiver6); int value7 = digitalRead(laserReceiver7); /////////////////Condition for laserReceiver1 and led1///////////////// if (value1 == 1) { digitalWrite(led1, HIGH); } if (value1 == 0) { digitalWrite(led1, LOW); } /////////////////Condition for laserReceiver2 and led2///////////////// if (value2 == 1) { digitalWrite(led2, HIGH); } if (value2 == 0) { digitalWrite(led2, LOW); } /////////////////Condition for laserReceiver3 and led3///////////////// if (value3 == 1) { digitalWrite(led3, HIGH); } if (value3 == 0) { digitalWrite(led3, LOW); } /////////////////Condition for laserReceiver4 and led4///////////////// if (value4 == 1) { digitalWrite(led4, HIGH); } if (value4 == 0) { digitalWrite(led4, LOW); } /////////////////Condition for laserReceiver5 and led5///////////////// if (value5 == 1) { digitalWrite(led5, HIGH); } if (value5 == 0) { digitalWrite(led5, LOW); } /////////////////Condition for laserReceiver6 and led6///////////////// if (value6 == 1) { digitalWrite(led6, HIGH); } if (value6 == 0) { digitalWrite(led6, LOW); } /////////////////Condition for laserReceiver7 and led7///////////////// if (value7 == 1) { digitalWrite(led7, HIGH); } if (value7 == 0) { digitalWrite(led7, LOW); } } void blinkMode() { //(Lights every stair with ascending and disensic order) digitalWrite(laser, HIGH); int delay1 = 30; if (digitalRead(laserReceiver1) == 1 && checkLights == 0) { digitalWrite(led1, HIGH); delay(delay1); digitalWrite(led2, HIGH); delay(delay1); digitalWrite(led3, HIGH); delay(delay1); digitalWrite(led4, HIGH); delay(delay1); digitalWrite(led5, HIGH); delay(delay1); digitalWrite(led6, HIGH); delay(delay1); digitalWrite(led7, HIGH); ascending = 1; checkLights = 1; } if (digitalRead(laserReceiver7) == 1 && checkLights == 0) { digitalWrite(led7, HIGH); delay(delay1); digitalWrite(led6, HIGH); delay(delay1); digitalWrite(led5, HIGH); delay(delay1); digitalWrite(led4, HIGH); delay(delay1); digitalWrite(led3, HIGH); delay(delay1); digitalWrite(led2, HIGH); delay(delay1); digitalWrite(led1, HIGH); ascending = 0; checkLights = 1; } if (digitalRead(laserReceiver1) == 0 && digitalRead(laserReceiver2) == 0 && digitalRead(laserReceiver3) == 0 && digitalRead(laserReceiver4) == 0 && digitalRead(laserReceiver5) == 0 && digitalRead(laserReceiver6) == 0 && digitalRead(laserReceiver7) == 0 && checkLights == 1) { if (ascending == 1) { digitalWrite(led1, LOW); delay(delay1); digitalWrite(led2, LOW); delay(delay1); digitalWrite(led3, LOW); delay(delay1); digitalWrite(led4, LOW); delay(delay1); digitalWrite(led5, LOW); delay(delay1); digitalWrite(led6, LOW); delay(delay1); digitalWrite(led7, LOW); checkLights = 0; } else if (ascending == 0) { digitalWrite(led7, LOW); delay(delay1); digitalWrite(led6, LOW); delay(delay1); digitalWrite(led5, LOW); delay(delay1); digitalWrite(led4, LOW); delay(delay1); digitalWrite(led3, LOW); delay(delay1); digitalWrite(led2, LOW); delay(delay1); digitalWrite(led1, LOW); checkLights = 0; } } } void PhotoresistorNormal() { //(Lights each led every time a stair has been activated) GetAverageLight(); Serial.print("checklight "); Serial.print(checklight);Serial.print(" "); if (average < 700) { digitalWrite(laser, LOW); digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); digitalWrite(led5, LOW); digitalWrite(led6, LOW); digitalWrite(led7, LOW); checklight = 0; } else if (average > 900) { NormalMode(); } } void PhotoresistorBlink() { //(Lights each led every time a stair has been activated) int value = analogRead(PhotoResistorPin); GetAverageLight(); Serial.print("checklight "); Serial.print(checklight);Serial.print(" "); if (average < 700) { digitalWrite(laser, LOW); digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); digitalWrite(led5, LOW); digitalWrite(led6, LOW); digitalWrite(led7, LOW); checklight = 0; } else if (average > 900) { blinkMode(); } } void test() { // test mode digitalWrite(laser, HIGH); int value1 = digitalRead(laserReceiver1); int value2 = digitalRead(laserReceiver2); int value3 = digitalRead(laserReceiver3); int value4 = digitalRead(laserReceiver4); int value5 = digitalRead(laserReceiver5); int value6 = digitalRead(laserReceiver6); int value7 = digitalRead(laserReceiver7); int value = analogRead(PhotoResistorPin); Serial.print("LIGHT "); Serial.print(value); Serial.print(" sensors "); Serial.print(value1); Serial.print(value2); Serial.print(value3); Serial.print(value4); Serial.print(value5); Serial.print(value6); Serial.print(value7); Serial.print(" "); GetAverageLight(); /////////////////Condition for laserReceiver1 and led1///////////////// if (value1 == 1) { digitalWrite(led1, LOW); } if (value1 == 0) { digitalWrite(led1, HIGH); } /////////////////Condition for laserReceiver2 and led2///////////////// if (value2 == 1) { digitalWrite(led2, LOW); } if (value2 == 0) { digitalWrite(led2, HIGH); } /////////////////Condition for laserReceiver3 and led3///////////////// if (value3 == 1) { digitalWrite(led3, LOW); } if (value3 == 0) { digitalWrite(led3, HIGH); } /////////////////Condition for laserReceiver4 and led4///////////////// if (value4 == 1) { digitalWrite(led4, LOW); } if (value4 == 0) { digitalWrite(led4, HIGH); } /////////////////Condition for laserReceiver5 and led5///////////////// if (value5 == 1) { digitalWrite(led5, LOW); } if (value5 == 0) { digitalWrite(led5, HIGH); } /////////////////Condition for laserReceiver6 and led6///////////////// if (value6 == 1) { digitalWrite(led6, LOW); } if (value6 == 0) { digitalWrite(led6, HIGH); } /////////////////Condition for laserReceiver7 and led7///////////////// if (value7 == 1) { digitalWrite(led7, LOW); } if (value7 == 0) { digitalWrite(led7, HIGH); } delay(20); }
This project was made for 7 stairs so you have to adjust if you have more stair by using more Arduino nano or get an Arduino mega which has more pinouts
Use the below images to see how I use the Arduino nano. The code is adjusted to these diagrams
Concerning cable management I designed in fusion 360 the above channels used for hiding the cables used for lighting and sensors.