Project Overview
This project creates an automatic staircase lighting system that turns on LED strip lights when someone approaches the stairs and turns them off after a set delay. Perfect for improving safety on stairs at night while saving energy.
Difficulty: Beginner
Estimated time: 2-3 hours
Estimated cost: $25-35
How It Works
The system uses two PIR sensors placed at the top and bottom of the stairs. When a sensor detects motion, it triggers the LED strip to turn on. A microcontroller tracks which direction the person is moving and can optionally light only the relevant portion of the stairs. The lights turn off after a set period of no motion.
Materials Needed
- Arduino Uno or ESP32 (1)
- HC-SR501 PIR sensors (2) – one for top, one for bottom
- LED strip (5V or 12V, length to match your stairs) – WS2812B addressable or simple RGB strip
- MOSFET or relay module (if using 12V LED strip)
- 5V/12V power supply (depending on LED strip voltage)
- Jumper wires
- Project enclosure for Arduino (optional)
- Mounting brackets or adhesive tape for sensors and LED strip
Circuit Diagram
Connection Table (Arduino Uno)
| Component | Pin | Arduino Pin |
|---|---|---|
| Top PIR | VCC | 5V |
| Top PIR | GND | GND |
| Top PIR | OUT | Digital Pin 2 |
| Bottom PIR | VCC | 5V |
| Bottom PIR | GND | GND |
| Bottom PIR | OUT | Digital Pin 3 |
| LED Strip (5V) | VCC | 5V (or external supply) |
| LED Strip (5V) | GND | GND |
| LED Strip (5V) | DATA | Digital Pin 6 (for addressable) |
Wiring Notes
If using a 12V LED strip, connect it to an external 12V power supply and use a MOSFET or relay module to switch it on/off. The MOSFET gate connects to an Arduino digital pin.
Arduino Code
// Automatic Staircase Lighting with PIR Sensors
// Uses two PIR sensors at top and bottom of stairs
const int topPIR = 2;
const int bottomPIR = 3;
const int ledPin = 6; // For simple LED strip control
// For addressable LEDs, include the FastLED library
unsigned long lastMotionTime = 0;
const unsigned long lightTimeout = 10000; // 10 seconds
bool lightsOn = false;
void setup() {
pinMode(topPIR, INPUT);
pinMode(bottomPIR, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600);
Serial.println("Staircase Lighting System Ready");
Serial.println("Waiting 60 seconds for sensor warm-up...");
delay(60000); // Allow sensors to stabilize
}
void loop() {
bool topDetected = digitalRead(topPIR) == HIGH;
bool bottomDetected = digitalRead(bottomPIR) == HIGH;
if (topDetected || bottomDetected) {
// Motion detected - turn on lights and reset timer
if (!lightsOn) {
digitalWrite(ledPin, HIGH);
lightsOn = true;
Serial.println("Lights ON");
}
lastMotionTime = millis();
// Optional: print direction
if (topDetected && !bottomDetected) {
Serial.println("Motion at TOP of stairs");
} else if (bottomDetected && !topDetected) {
Serial.println("Motion at BOTTOM of stairs");
} else if (topDetected && bottomDetected) {
Serial.println("Motion at BOTH ends");
}
}
// Check if lights should turn off
if (lightsOn && (millis() - lastMotionTime > lightTimeout)) {
digitalWrite(ledPin, LOW);
lightsOn = false;
Serial.println("Lights OFF");
}
delay(100); // Small delay to debounce
}
Code for Addressable LED Strips (WS2812B)
#include <FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 20 // Change to match your strip length
#define BRIGHTNESS 64
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
const int topPIR = 2;
const int bottomPIR = 3;
unsigned long lastMotionTime = 0;
const unsigned long lightTimeout = 10000;
bool lightsOn = false;
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
pinMode(topPIR, INPUT);
pinMode(bottomPIR, INPUT);
// Turn off all LEDs
FastLED.clear();
FastLED.show();
Serial.begin(9600);
delay(60000); // Sensor warm-up
}
void setLightColor(int startLED, int endLED, CRGB color) {
for (int i = startLED; i <= endLED; i++) {
leds[i] = color;
}
FastLED.show();
}
void loop() {
bool topDetected = digitalRead(topPIR) == HIGH;
bool bottomDetected = digitalRead(bottomPIR) == HIGH;
if (topDetected || bottomDetected) {
if (!lightsOn) {
// Turn on all LEDs
setLightColor(0, NUM_LEDS-1, CRGB::White);
lightsOn = true;
}
lastMotionTime = millis();
}
if (lightsOn && (millis() - lastMotionTime > lightTimeout)) {
// Fade out effect
for (int b = BRIGHTNESS; b > 0; b -= 5) {
FastLED.setBrightness(b);
FastLED.show();
delay(30);
}
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
lightsOn = false;
}
delay(100);
}
Installation Steps
- Mount the sensors: Place one PIR sensor at the top of the stairs and one at the bottom. Mount them at 1.5-2m height, angled to cover the stair approach area.
- Install LED strip: Attach the LED strip along the stair stringer, under the handrail, or along the stair treads. For best effect, mount under the handrail so light illuminates the steps without glare.
- Run wiring: Connect sensors to the Arduino using 3-conductor cable. For long runs, use thicker wire (22 AWG or larger) to prevent voltage drop.
- Power supply: Place the Arduino and power supply in a weatherproof enclosure near a power outlet. Ensure the power supply can handle the LED strip current (calculate: 60mA per LED for WS2812B).
- Upload code: Connect Arduino to computer, upload the code, and test sensor function.
- Adjust settings: Modify
lightTimeoutto change how long lights stay on. Adjust sensitivity pots on PIR sensors as needed.
Troubleshooting
- Sensor not detecting: Check wiring and ensure 60-second warm-up has completed. Adjust sensitivity potentiometer clockwise to increase range.
- False triggers: Ensure sensors aren’t facing heat sources (vents, windows). Reduce sensitivity or add a 0.1µF capacitor across VCC and GND near each sensor.
- Lights flickering: Power supply may be inadequate for LED strip current. Use a higher-rated power supply or reduce brightness in code.
- Sensor detects too far: Adjust sensitivity potentiometer counter-clockwise to reduce range.
Project Extensions
- Directional lighting: Light only the steps from the sensor that detected motion. This requires addressable LEDs and tracking which sensor triggered.
- Color temperature adjustment: Use warm white (2700K) at night, cooler white during the day using a real-time clock module.
- Smart home integration: Use an ESP32 instead of Arduino and integrate with Home Assistant or Alexa for remote control and scheduling.
- Music synchronization: Add a microphone module to make lights respond to music (great for parties).
- Motion-activated music: Add a DFPlayer Mini module to play a welcome message or music when motion is detected.
Conclusion
This automatic staircase lighting project improves safety and adds a modern touch to your home. The system can be installed in a weekend and customized to match your home’s decor. With proper installation, it will provide years of reliable service.
