Automatic Hallway Runner Lights

188,960

1,497

36

Posted

Introduction: Automatic Hallway Runner Lights

You know how it goes - you wake up in the middle of the night to go to the bathroom, can't see anything, and knock something valuable over. Or, you come home late, the lights are already off, and you stub your toe trying to find the switch.

No longer! We've solved the problem of late-night lighting in a hands-free way that's stylish and won't disturb your roommates.

Like this Instructables? Check us out on Facebook!



Introducing the Automatic Hallway Runner Lights.

Total project time: 3 hours

To get started, you'll need the following parts:

Some tools:

  • Breadboard for prototyping
  • Soldering iron (and solder)
  • Wire strippers/cutters
  • Heat gun (or hairdryer, or lighter)
  • Hot glue gun (to secure loose wires)

Step 1: Build the Circuit

Now that you have all your parts in hand, it's time to build the lighting controller!  This circuit turns the runner lights on or off depending on the current light levels in the hallway (detected by the photocell) and the presence of a moving object (detected by the PIR sensor).

Step 1: Headers
We want to mout the arduino to the protoboard using two of the female header sockets. Align two of the headers so that pins D7 to TX and A2 to VIN will be connected to the board when the arduino is plugged in, then solder them in place. Next,  take another 10-pin female header and cut it into two 2-pin sockets and one 3-pin socket. Install these three sockets; the photocell and LED strip both need two pins, and the PIR sensor needs the three-pin socket. 

Step 2: Cables
We wanted the PIR sensor and photocell to be mounted pretty far away from the board and the LED strip - about 10 feet away! If you want everything near the PCB, you can skip this part.

We'll need to create two cables - one for the PIR sensor which has 3 wires, and one for the photocell with two wires. The photocell is easy - just cut a 10-foot length of our 2-conductor stranded wire. Strip one end and separate the leads before slipping some heat shrink tubing on for later. Then solder the two leads of the photocell, move the heat shrink over the solder joints, and heat it up to ensure a solid, insulated connection. For the other end, break off a 2-pin segment of the male header pins, strip the two conductors and solder each conductor to one of the pins. Add some some hot glue around the solder connection to ensure nothing will accidentally short these two leads.

It's a similar process to create a cable for the PIR sensor, but this time we want to use our 3-conductor stranded wire for each of the pins of the PIR sensor. Follow the same steps as before, but Instead of soldering the PIR sensor directly to the wire, cut a 3-pin female socket segment and solder this to the cable instead. The pins of our PIR sensor should fit nicely into this socket.

Step 3: Connections
Use your iron and some solid core wire to install and connect the remaining parts as indicated in the diagram.

Some justifications:
Our PIR sensor's output pin reads 0V when no motion is detected and 5V when it senses a moving object. We could just feed this value straight into a digital input pin on the Arduino Nano, but we noticed that there was a large drop in power due to the 10'+ of wire we used to put the sensor in place. Instead, We hooked the sensor up to A6 and used analogRead() to check if the voltage is above or below a certain threshold. 

The photocell is triggered in a similar way - combined with the resistor, it acts as a voltage divider. When there's a lot of ambient light, the photocell has low resistance and we see a low voltage; in the dark, we see close to 5V.

When we send a digital HIGH (5V) value on pin D3, that saturates our MOSFET and allows current to flow through the LED strip. The 100kOhm resistor attached to its gate acts as a pull-down, so that our LEDs actually turn off if the gate ends up floating. 

Step 2: Program the Arduino

With your circuit fully built, it's time to give this project a brain..

We've attached the code we used for the Arduino. Note that it contains two parameters that you're free to customize to your needs and situation: LIGHT_THRESH (how light sensitive it is - increasing sensitivity means that it'll need to be darker to activate) and TIMEOUT (how long the lights remain on after detecting motion - increasing it will cause the lights to stay on for longer).

With VIN disconnected, upload this code to the Arduino. Open up the serial monitor and see what the values become in high and low lighting, then set your threshold to match. Make sure to test this as close as possible to where you're installing the sensors - lighting conditions can change drastically in the space of a few feet.

When you have a threshold you think works, disconnect your Arduino from your computer and connect it to the 12V supply. Your LED strip should now be light- and motion-sensitive! 

Here's the Arduino code we used:

// Automated Runner Lights (v1.0)
// Scott Martin & Todd Medema
// http://fabricate.io
// 10/3/2013
//
// Change this code to your heart's content!

// Constants won't change. They're used here to
// set pin numbers and thresholds:
const int motionPin = 6;// A6
const int lightAnalogPin = 7; // A7
const int ledPin = 3; // D3
const int LIGHT_THRESH = 1000;
const int MOTION_THRESH = 250;
const int TIMEOUT = 1000;

// variables will change:
int motionState = 0; // countdown after last motion
int lightState = 0; // countdown after last dark
int LEDActive = 0; // if LEDs are on
int LEDBrightness = 0; // current LED brightness (for fade in/out)

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop(){
  if (analogRead(motionPin) > MOTION_THRESH) {
    motionState = TIMEOUT;
  }
 
  if (analogRead(lightAnalogPin) < LIGHT_THRESH) { //Is Bright
    lightState = 0;
  } else {
    lightState = TIMEOUT;
  }
  if (motionState > 0) motionState -= 1;
  if (lightState > 0) lightState -= 1;
 
  Serial.print("cell: ");
  Serial.print(analogRead(lightAnalogPin));
  Serial.print(", pir: ");
  Serial.println(analogRead(motionPin));

  if (motionState && (lightState || LEDActive)) {    
    LEDActive = true;
  }
  else {
    LEDActive = false;
  }
  if (LEDActive) {
    if (LEDBrightness < 255) {
      LEDBrightness = min(LEDBrightness + 1, 255);
    }
  } else {
    if (LEDBrightness > 0) {
      LEDBrightness = max(LEDBrightness - 1, 0);
    }
  }
  analogWrite(ledPin, LEDBrightness);
 
  delay(10);
}

Step 3: Install the Lighting

So far, we've built the circuit and programmed the arduino with the proper lighting thresholds. Now it's time to mount your LED strips!

You'll want to put your LED strip about 6 inches above the floor. Masking tape works fine to hold it to the wall - though, if you won't be moving out any time soon, the strip does have an adhesive backing that you can use. The lights are bright enough that you only need them on one side of a hallway, but feel free to light both sides of the hall if you have extra.

You can cut the strip up into pretty small sections (cut along the marked cut line) and reconnect the sections with wires. This lets you skip past doors by running the wiring over the door frame and continuing the strip on the other side.

Once you have the lights attached to the wall, try connecting them directly to the power supply and making sure all sections light up properly. If you discover a bad segment, check the connections between strips to make sure they're unbroken. If nothing lights up, you might have a short circuit! Disconnect the lights quickly and test the lights with a multimeter to make sure power and ground are separate.

We noticed that, when uncovered, the light strips are really bright and irritating to look at. We can fix that! Grab some computer printer paper, and cut it into 1.5" wide strips. Fold these strips in 1/3rds back on each other (have the two folds go in opposite directions so that you end up with a Z shape).

Take these strips and, using masking tape, secure them directly above the LEDs. This obscures the LEDs from the top and side, making them much less harsh to look at and focusing their light on the ground, where you want it to be!

Step 4: Sensors Installation & Recalibration

Now that we have the lights in place, install your sensors.

Ideally, the photocell should be in a place that accurately reflects the lighting of the entire hall - we placed ours close to the ceiling in the middle of the hallway. The PIR sensor should be placed in a location with a full view of the hallway, and an obstructed view of everywhere else. You might want to use paper or some other material to block a part of the sensor and prevent false lighting from people that walk near where you're trying to light.

After the mounting is finished, re-check your thresholds by following Step 2 in the instructable again. The values will probably have changed slightly. 

Step 5: Conclusion

Congratulations! You should now have some incredibly cool and functional runner lights along your hallway, letting you roam at night without bumping into things or disturbing your roommates!

As always, let us know in the comments if you have any questions or ideas for improvements. And we'd love to hear from you if you install a set of your own!

Did you like this Instructable? Don't forget to Favorite it and Follow us on Facebook!

Share

Recommendations

  • Microcontroller Contest

    Microcontroller Contest
  • Spotless Contest

    Spotless Contest
  • Science of Cooking

    Science of Cooking
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

31 Comments

In the process of putting this together but am adding some
special effects to it as I go along. I have a 21' hallway that I plan on
dividing up the LED strip into 18 lamp sections. At each end of the hallway
will be the PIR and depending on which direction you enter the hallway the PIR
activates the LED strip to sequence each section in the direction of your
travel. Eventually I will add additional PIR sensors to have each section light
up along the way while the prior LED section turns off behind you.

Awesome stuff! I'd like to use this to switch a TV on and off. I'm new to this stuff so please bare with me

I currently have a droidstick showing artwork from a twitterfeed on a dedicated tv in the livingroom which at the moment switches on using a regular timer in the power socket. Works great but does waste a bit of power if there's nobody there to enjoy the art, so I'd like to replace the socket timer with something like this creation using an infrared sensor or something so it switches on or off depending on whether there's someone in the room.

Is it just a matter of replacing the mosfet with this one: IRF840?

Hi Richard - sounds like a cool project :)

It sounds to me like you're trying to switch AC using a MOSFET - chances are this won't actually work and may damage both the circuit and your TV. I'd highly recommend using a relay instead, as these are designed to take AC loads. There are even solid state relays (SSRs) that can take tens of millions of cycles before failure and don't have that clicky sound when they turn on.

Wait Wait Wait... An Arduino Nano is $20 (£14)?? I thought paying the £3.50 ($4.90) was a bit steep (though with free shipping).

Yeah, in hindsight that was a pretty steep markup for a cheap little micro... the things you learn in 3+ years ;)

Thanks for pointing it out though - updated the pricing.

Nice one.. I felt a bit of a d*** for leaving that message after pressing enter key, but there was no edit, and delete kept failing. I am glad you didn't take it the wrong way. Nice project. I plan on doing something very similar but to the stairs.. I did have the idea of doing each step individually, but your project given me the idea of just doing the skirting board down the stairs.

What is the power draw when lights are off? Is this something to turn off in the daytime in other words? I am just curious if you have had a chance to measure the sleeping status of the circuit?

Haven't measured it directly, but the quiescent current of a PIR sensor is in the range of microamps. The nano uses < 1mA when active (https://www.reddit.com/r/arduino/comments/14hsiz/h...) so you're probably looking at spending under $0.01 per year for any idle time.

If you're counting converting AC to power it, that'll probably be higher, but the cost varies wildly depending on the efficiency of the adapter used.

While this is a great project, you don't need a computer to light up an LED.

Get one (or many!) of these PIR (motion detector) modules from eBay:

http://www.ebay.com/itm/10pcs-HC-SR501-Adjust-IR-P...

They have a switched output that will switch a highly efficient LED (quite bright) on when there is motion, and they have an adjustable delay before they go back off.

If they don't already have one, you can add an LDR (light dependent resistor) so the gadget doesn't turn the light on in the daylight hours or if the main overhead light is on.

No programming, and the only wires would be for a power connection unless you can run it on a local battery.

Great project here, but you don't need that much light to find a wall switch in the dark.

We actually used a similar sensor to that one for this project - but we wanted to go a bit more artistic. There's a huge difference between bang-on, bang-off for a single LED and slow-fading strip accent lighting.

Different strokes, I suppose :)