Wednesday 20 April 2022

Motion activated and timed staircase lights

Years ago, when I first started with electronics one of the first projects I did was to create some motion-activated lighting on the staircase.

It was a basic setup with stick-on LED lights, activated by a pressure pad under the carpet on the top and bottom step. This is a re-make and update of that project in my new home.

 

The lights

I recovered 6 under-counter lights from a kitchen renovation.

The fittings are for G4 bulbs, run off 12V AC, and have a nice chromed finish.

The bulbs were originally halogen, but I swapped them out for LEDs to reduce the power requirements.

As the lights are designed for AC voltage, they can also be driven by a DC supply to simplify the circuitry and make it easier for them to be micro-controlled, so in effect they will be little different to regular LEDs.

The staircase doubles back on itself, so the idea is to mount the lights in the middle partition, and then run the wiring to the control in the under-stairs cupboard. 

Because of the number of steps on the staircase, there will be one light every two steps starting at the second step.

This will put two lights on the bottom half of the stairs, one light on the middle landing, and then 3 on the larger upper half of the stands (as there are more steps on that half).

Routing the cabling

The main difficulty will be in routing the cable for the lights on the upper part of the staircase as it will be difficult to recess the lights without the cable needing to be threaded all the way through. Rather than run the cable all the way through, then have to recess it I opted for a method using the drill as illustrated in the graphic below - this minimizes the amount of material that was removed from the sides and reduces the amount of patching and filler that is required. 

The sensors 

To modernize the switching system, I am implementing a sensor system at the top and bottom of the staircase. I originally intended to use passive infra-red (PIR) sensors, however I don’t want the lights to be triggered just walking past the staircase, and these can be tricky to focus on a precise area.

Instead I’ve opted for ultrasonic distance sensors - not just like the ones used as car parking sensors, but literally those.

These systems typically contain four sensors, a control box, and a small LED display module.

There are several others who've made efforts to interpret the pulsed signal from the control box. I initially tried to follow a similar approach with mine, however was unable to get the example code working - it seems perhaps the sensors I have were either using a different PWM speed or encoding system.

As I do not care too much about measuring the exact difference, and am treating them more like a 'beam-break' sensor, I can take a rougher approach to detecting motion.


After some prodding with an oscilloscope I found a couple of pins that showed a square waveform that appeared to react suitably to me waving my hand in front of the sensors.

I put together a simple arduino sketch to read the rising and falling edge of those waveforms, and simply counted the transitions.

This is a rather effective, but admittedly hacky, solution - basically just observe the range that the transitions are when there's no obstruction in front of the sensor, what the value is when the sensor detects something, and then simply if/else on the value to detect if the sensor has been triggered.

Lighting Pattern and Timing

The lights will be patterned to switch one at a time, starting at either the bottom or top of the stairs (depending on which sensor is triggered), remain on for approximately 10 seconds, and then switch off in the same order. 

The Circuit


The Code

As usual, the code is available on GitHub.