Automated StairLights…the easy way with an Arduino Pro Mini

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.

Enjoy!

#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);
SoftPWMBegin();
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)
climb();
if (topsensorState == HIGH)
descend(); }

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

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

Advertisements

5 thoughts on “Automated StairLights…the easy way with an Arduino Pro Mini

  1. Thanx!
    just tried the code but while compiling i did receive an error :

    exit status 1
    ‘descend’ was not declared in this scope

  2. Here you go.
    //---------------------------------------
    // StairLights v1.0
    //
    // by Darren Mathews
    //
    // Nov 29, 2013
    //
    // v1.0 initial release
    //---------------------------------------

    #include

    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);
    SoftPWMBegin();
    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)
    climb();
    if (topsensorState == HIGH)
    descend();
    }

    void climb() {
    for (int i = 0; i < 12; i++) {
    SoftPWMSet(leds[i], 255);
    delay(loopDelay);
    }
    delay(10000);
    for (int i = 0; i = 0; i--) {
    SoftPWMSet(leds[i], 255);
    delay(loopDelay);
    }
    delay(10000);
    for (int i = 11; i >= 0; i--) {
    SoftPWMSet(leds[i], 0);
    delay(loopDelay);
    }
    }

  3. For several years i find myself browsing for different DIY projects, and stair light is 1 of them. Just recently i ordered some NANO 3.0 (arduino) goodies and want to finally start building this. At the moment i’m also in the early fases of home automation so this will be a nice extra!
    To be honest i don’t have any experience with “arduino-like” builds right now, but when i receive the parts i probably will be spending many (late) hours “playing” with it.
    I was pleasantly surprised that i have found your project and want to duplicate it.
    Here in the comments i saw that someone else also tried it and wasn’t able… Maybe it’s not my place to ask but is it possible to receive the working code ?
    Many thanks in advance and kind regards,

    Remco

  4. Sorry for the delayed response. The comments are tied to an older email address I haven’t checked in weeks. Let me know if you still need help.

  5. Hi, your method is really the easy way!!!! The SoftPWM Library is perfect for this project!
    I just have a problem with your code, there are some errors when verify…
    Can you help me?
    Thanks!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s