Every now and again I'm required to put on my thinking (bobble) hat in order to achieve the functionality a client wants. Such was the case here where automatic LED lighting was required on a stairwell necessitating the design of a simple custom controller.
This customer’s property is a listed building currently under renovation, but one stairwell was proving something of a headache for lighting. The client wanted each step to be illuminated, but two-way manual switching would have been clumsy as switching for follow-on lighting at the top and bottom of the stairs is a distance away from the stairwell. In short, you’d turn on the lighting to ascend or descend the stairwell, then when you got to the end if you turned off the lighting behind you, you’d have to cross a dark section of room to get to the next switching point.
A sensor arrangement was deemed to be a more elegant solution as the stairwell lighting could operate automatically as someone approached, then hold the lights on for long enough afterwards to enable the user to cross to the next switching point. A spanner in the works for this plan however was the awkwardness of getting 230V cabling to the sensor positions. It could be done of course but keeping cabling in prescribed zones would be awkward in this particular case.
Instead, I decided to run the whole thing at 12V so the cables didn't need to be zoned, and use off-the-shelf intruder alarm PIR sensors for motion detection.
The problem with using intruder alarm sensors for switching lighting is that they work opposite to how we want; they switch ‘off’ when they detect movement rather than switching on. In an alarm system, the control panel sends out a voltage to the normally closed relay in the sensor which returns the voltage to the panel because the relay is.... well... normally closed, so, we have a closed loop under normal conditions. When the sensor detects movement, it opens the relay, the panel detects the loss of continuity in the loop and the alarm sounds.
Typical contact arrangement in an intruder alarm PIR
The tamper network operates in the same way with both (T) terminals being connected to a closed switch in an alarm setup. If the cover is opened on the PIR, the switch opens, and the alarm panel detects the loss of continuity and sounds the tamper alarm. We’re not using the temper terminals here, but that’s how they work.
This closed-loop feature of security systems allows the alarm panel to detect when a cable has been cut as loss of either loop would result in an alarm condition. For this application however, we’re going to need to reverse this operation as we need the opening of the relay contact to turn the lights on, so we’ll be using a NOT AND (NAND) logic gate. We’ll also need some kind of basic timing mechanism to ensure the lights remain on a little longer than the sensors which only change their output state while movement is being actively detected. Should someone pause on the stairs, we don’t want the lights to suddenly extinguish and plunge them into darkness! Here's what was designed for this task with a handful of basic components that were ready to hand:
The design of this circuit is scalable. I’m using two sensors, but any number could be applied so long as each has its own individual connection to an input at the logic (NAND) gate.
Each gate input is held high by the senor under normal conditions as the 12V line passes through the sensor's normally closed relay. With all inputs high, the output of the gate is low because of its NOT function as shown in the truth table below.
A | B | NAND OUTPUT |
0 | 0 | 1 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
Ultimately, the LED lighting will turn on and off in sympathy with the gate output, so the gate output being low means the LED lighting is off. More on that later.
When either sensor detects movement, it opens its relay and the 12V line to the related gate input is lost resulting in the input line being pulled low by a 1k resistor. Any input line dropping low causes the output of the gate to switch on as the truth table shows. The gate output going high has two functions, firstly it switches on the transistor via a 7.5k resistor. This provides a path to ground for the LED’s via the transistor CE junction, thus allowing the LED’s to illuminate. Secondly, it quickly charges a large capacitor.
So long as one or more sensor continues to detect movement, the gate will remain on and so will the LED lighting, however once the motion event has lapsed, the sensor(s) relay will once again close, sending 12V back to the gate input(s) turning the logic gate off again. Rather than the LED lights snapping off at this point, the charged capacitor now begins discharging through the transistor keeping the CE junction open so the LED’s remain on for longer. The diode prevents the capacitor from feeding back into the logic gate.
The capacitor’s voltage drops as it discharges, but it keeps the transistor saturated for a period of time before it is no longer able to hold the CE junction fully open. As the capacitor voltage drops further, the resistance of the CE junction begins to rise, and this increasing resistance in series with the LED lighting causes the light output to dim proportionally.
What all this means is the LED lighting is held on for several seconds after the last movement was detected before gradually fading off, so we have our timing element followed by an aesthetic fade out of the lights afterwards. The timing and fading can be reduced or extended by the use of a smaller or larger capacitor respectively.
A wobbly video showing the lights being held on for several seconds after the stairwell
was last used, followed by the gradual fade out as the capacitor discharges through the transistor. Once
fully refurbished, this stairwell should look pretty good
For the stairwell tread lights, decking lighting has been used, these units each having a cluster of five 5mm LED elements for a power consumption of about 0.5W. Eleven modules are connected in parallel for a total of 5.5W. In addition to this, at the top of the stairs is a 1.3W MR16 LED cluster lamp mounted in the ceiling, so the overall total lighting load is 6.8W (0.56A) which is an acceptable load for the BFY51 transistor rated at up to one Ampere. For larger loads, different components will have to be considered.
Circuit construction on stripboard. The pin outs for the terminals are (from top):
12V, GND, Sensor 1 return, Sensor 2 return and LED ground
For the logic gate, I have used a CMOS IC because of the 12V supply. A 4011 quad two-input NAND was the IC of choice as that was what was available off-the-shelf, however only one of the four gates has been employed here. Alternative ICs would be the 4012 dual four-input IC (two gates, each with four inputs), the 4023 triple three-input IC, or the 4068 single eight-input IC which is perhaps the best option as it has no idle gates and offers the most scalability. Importantly, any gate inputs that are not in active use must be tied to the 12V line and not left floating.
On site, and fitted into an insulated pattress mounted specially within the wall. The feed is via a 3A fuse unit to the right,
and a 15W 12V driver is also located in the pattress above the circuit board. A two-gang blank plate will
cover it over, leaving the decorator to pretty up around the accessories afterwards
Only three wires are required for each sensor, +12V, GND and the 12V return from the relay. An internal link needs to be installed in the sensor to link the 12V line to the other side of the relay.
There are other ways to achieve this kind of operation, but the seven components here were readily available and only cost a few pence. Construction was quick, and the client is very happy with the installation. It'll be a long time before the refurbishment is finished, but I'll upload a better video of it all in operation once the project is completed.