Motion Activated LED Strip

Intro: Motion Activated LED Strip

Goal

There are stairs up to where I live and during the winter and at night they can be treacherous. I wanted an easy method to illuminate the stairs — imagine your hands are full of groceries — while also not having to go back and turn them off.

Overview

Basically I ran an LED strip down the railing of my stairs. At one end, you walk past an Obstacle Avoidance Sensor (you need to be within <5 inches) which an Arduino Nano listens for and triggers a Relay to turn on the LEDs for 30 seconds. All housed within a coffee container for "decent" weatherproofing. That's it! More details below...

Step 1: Supplies

Necessary

Not Required

Step 2: Wiring Diagram

Organization

  • Arduino and Relay are on PCB
  • Collision Detector is connected via wires

Step 3: Plan Component Placement and Begin Wiring

  1. I placed the Arduino at one end; and with a little space marked where I wanted the relay
  2. With some putty to hold things in place, I soldered the wires

Step 4: More Wiring and Soldering

  1. I added the wires that were going to connect to the Collision Detector
  2. Soldered in the relay
  3. I made the connections to the Arduino by tracing solder, not too pretty but seems to work
    1. Notice how the 5V pin is connected to both

Step 5: Finishing Up

This image shows melted holes in the coffee can.

Also notice that the DC power cable to the LEDs has been spliced. Ground is wired together, and positive is split. I soldered the exposed wires to add slight durability. These will be screwed into the relay.

And finally the code:

motion-led.ino

// This Timer.h library came from here: https://github.com/JChristensen/Timer
#include"Timer.h"
#defineavoidPin4
#definerelayPin5
#definedelayMs100
#definetimeoutMs1000 * 30
int lastValue;
bool isTimerRunning = false;
Timer mainTimer;
Timer workTimer;
voidsetup()
{
Serial.begin(115200);
pinMode(relayPin, OUTPUT);
pinMode(avoidPin, INPUT);
Serial.println("Set pins in setup mode, listening every ms: " + String(delayMs));
mainTimer.every(delayMs, mainCallback);
}
voidmainCallback() {
int avoidVal = digitalRead(avoidPin);
// We only care if something changes (someone walks in front of the sensor)
if (avoidVal != lastValue) {
// It's different, is the timer running?
if (isTimerRunning) {
Serial.println("Don't need to do anything, timer is running");
}
else
{
// Timer not running, is somebody there?
if (avoidVal == LOW) {
digitalWrite(relayPin, HIGH);
// Start a timer to turn them off
workTimer.every(timeoutMs, workCallback, 1);
isTimerRunning = true;
Serial.println("LED is on, timer started, bool set");
} else {
Serial.println("Looks like nobody is there, not starting timer");
}
}
lastValue = avoidVal;
}
// If they are the same value who cares, we only care about things that change
}
voidworkCallback() {
isTimerRunning = false;
digitalWrite(relayPin, LOW);
Serial.println("LED off and bool = false");
}
voidloop()
{
mainTimer.update();
workTimer.update();
}
view rawmotion-led.ino hosted with ❤ by GitHub

Share

    Recommendations

    • Fix It! Contest

      Fix It! Contest
    • Tiny Home Contest

      Tiny Home Contest
    • Metalworking Contest

      Metalworking Contest

    Discussions