There are numerous examples online for how to do stairwell lights. Some are expensive, some are complicated, some are well done, but still too much for my taste. You can buy a system ready-made, which can be very expensive or DIY. If you’re reading this, like me, you’d probably rather DIY.

I first read through Erica Kane’s project which is very well done, but a bit too much to simply light a few LEDs. Surely there has to be a simpler way to accomplish the same effect. Her code is rather long and involves more than what’s needed….for me.

I wanted a fade effect for each light that ramps up to full brightness, then turns off the same way. My code does this. The top or bottom stair sensor triggers the climb/descend code loop that then lights the stair lights in order fading them from off to on and leaves them on for the duration of a set delay. You can certainly adjust the delay if you’re a bit slow on the stairs. 😉

I’m using an Arduino Pro Mini, bought at the 20% off Cyber Monday sale at Sparkfun. In fact, I bought as many as they allowed per customer.

What’s needed:
Arduino Pro Mini – I only needed 12 pins it has just enough
Flush mount LED Bolt – 12 pre-wired, bright, flush, small, sweeeet
100 ohm resisters – 12
SainSmart HC-SR04 – distance sensor to activate lights
SoftPWM Library – Arduino library that simulates PWM functions on all pins

The code currently(Jan 8, 2014) doesn’t include the SainSmart sensor code, just a simple line as I was testing and using just a small button as my sensor trigger. I don’t actually have this installed in my house just yet, but wanted to share my code and progress.

Essentially, 12 LEDs connected one per pin to the Arduino. The SainSmart sensor detects a step on either the top or bottom step, then quickly lights the LEDs one at a time going up or down the stairs until their all on. A delay can be adjusted to slow or speed up how quickly all of the lights turn on, as well as how slow or fast the leds ramp up the fade delay. I’ll add the correct sensor code soon. What’s really impressive is the SoftPWM that essentially turns all of the digital pins into PWM pins to allow for the fade. It’s very smooth, you wouldn’t be able to tell those are digital pins at all.


#include <SoftPWM.h>

// numbers represent PINS used on Arduino, just
// order them to match as wired up on your stairs
uint8_t leds[12] = {9,8,7,6,5,4,3,2,10,11,12,13};
const int loopDelay = 100;
const int bottomsensorPin = A0;
const int topsensorPin = A1;
int bottomsensorState = 0;
int topsensorState = 0;

void setup() {
pinMode(bottomsensorPin, INPUT);
pinMode(topsensorPin, INPUT);
for (int p = 0; p < 12; p++)
SoftPWMSet(leds[p], 0);
SoftPWMSetFadeTime(ALL, 50, 400); }

void loop() {
bottomsensorState = digitalRead(bottomsensorPin);
topsensorState = digitalRead(topsensorPin);
if (bottomsensorState == HIGH)
if (topsensorState == HIGH)
descend(); }

void climb() {
for (int i = 0; i < 12; i++) {
SoftPWMSet(leds[i], 255);
for (int i = 0; i < 12; i++) {
SoftPWMSet(leds[i], 0);
} }

void descend() { for (int i = 11; i >= 0; i–) {
SoftPWMSet(leds[i], 255);
for (int i = 11; i >= 0; i–) {
SoftPWMSet(leds[i], 0);
} }