Some years ago my wife and me added some more space to our house. When planning we added several main power connections to the new rooms and wired a KNX cable beside any mains cable.
This is really nice. It made cabling the mains pretty simple as you only needed to route the mains to any consumer and the KNX (Wikipedia: KNX) also to any switch. It greatly reduced the cables needed even if designed for more total power consumption. Instead of a tree-layout of the cabling we have a trail for each of the power domains.
This is possible as the switches do not directly switch the power to i.e. a lightbulb, but send a command at the lightbulb’s socket to turn on or off that bulb. This works great and allows to control the lights or shutters from multiple locations without creating a cross-switch circuit.
Yet we used a lot of NYM cable and well the green twisted pair to control the KNX:
To make the installation more comfortable we have a KNX to ethernet bridge, which routes the KNX Packets into a protected WLAN. This is not reachable from the outside or by any other unprotected ports or WLANs. This allows us to turn off any light or move any shutter with our smartphones if we are logged in at home.
Since this is an old house we extended, these nice features are only within the new parts. Any light and any shutter in the old part of the house can only be operated at the existing switches.
We would like to change that but don’t want to open up all walls and add new cabling for the KNX control – again.
To archieve that I designed a little board to control mains power and to send control packets to through the KNX network to the designated target via ZigBee. This board will have to be placed in all the switches that shall be used as control or to be controlled by KNX.
To make things difficult, all old connections are routed through pretty small housings. A switch or outlet is sitting inside a 50mm diameter, 39mm deep housing, occupied almost completely by the outlet or switch. This leaves only about 10mm of depth and about 43-44mm diameter, so the wires will not be blocked by the new electronics.
My requirements are:
- Fit into 43mm diameter x 10mm depth
- Switch (lights only for now) 1 phase of 250VAC, max 1kW
- Detect state of an existing 250VAC rated, mechanical switch
- Be 250VAC tolerant on any input, yet allowing the switching input to be operated at an IO voltage of 3.3V
The size requirement was an immediate backlash, as I was planning to add a small transformer to be mounted on the PCB, but the smallest I could find were ~15mm in height. This was a no, since i would have to open up the wall to fit it in deeper – something neither me nor my wife wanted.
Cheap chinese electronics often use a capacitive resistance on the mains to drive LEDs. This method is very very unsafe if it is anywhere exposed to human touch, as mains is used as ground either after a bridge rectifier or even simpier, plain from one of the mains lines. This is not of any concern to me, as the board will be mounted behind a mains switch with 250VAC lines that are not even insulated i.e. at screws.
But what if any electrician would need to maintain the switch after we no longer were. He wouldn’t expect a board hanging behind a switch and may touch the board without protection and be electrocuted. The board has to be embedded into a casing of some kind.
3D-Printing to the rescue, a small case is done pretty quick. It has to be printed with a fire-retardant material.
Well that leaves me with even less space to put the electronics into. 42mm diameter and max 8mm height is the new limit.
The capacitive coubled power supply is pretty simple. A capacitance is used with its frequency dependend reactance. The frequency of the mains network is well knwon and very stable (50Hz @230Vrms, ~353Vpp here). We can calculate the required capacitance to allow only the required current.
With rectifying and a Zener Diode which is able to limit the voltage for that current we can stabalize the voltage and can supply it to the board. I.e. as shown below to 4.7V @ the same 35mA as above.
Sounds great. There are traps: The mains contains more than the 50Hz alone. Whenever anything is turned on or off, when inductive or capacative loads are used in the mains network, we have spikes and other dirt on the mains. That happens a lot.
In europe we have a standard that defined what the maximum dirt is on the mains for each frequency range. Mostly that is multiple of the 50Hz. For things like power line communication that can be some 10s of MHz and more.
This is a problem fro the reactance since it is frequency dependend. The higher the frequency, the lower the resistance. Leaving me with sub-Ohm resistances for the 100s MHz range. The power of any PLC would go straight into my cirquit.
To counter that I added a normal resistance into the path of 100Ohms. Given a load of ~5mA this would lead to 250mW to be dissipated at heat. This is greatly reducing the effectiveness. But on the other side any 100s MHz signal would now also be dampered by 100Ohms driving much less power into the cirquit itself.
Because of the loss at this added resistor, I better not draw too much current. The loss is calulcated as P = U*I. Since U is determinated by the resistor at the working current, P = (R*I) * I. This means double the current double the loss.
I need to drive a CC2538 for the zigbee. It has a max current draw of 35mA at 3.3V. This would be a loss of 100*0.035*0.035 W = 122mW … that is a lot, given that I only consume 115mW in the zigbee part, I have less than 50% efficiency.
I can reduce the current through the 100Ohms by using a step-down converter to generate the 3.3V. If I need 35mA at 3.3V I would need only 3.5mA at 33V, plus the loss because of the step-down converters efficiency. But at all around a decade less.
With 3.5mA the resistor now only dissipates 1.1225mW of heat. Great!
There is another problem. Remember that there are two methods to run the capactivive power supply? One with a bridge rectifier and one connecting the ground directly to one of the mains wires? Well I want to switch an output. I could do this either by a relais, or by a triac. The relais takes up a lot of space. Something I don’t have. So I need to drive a triac. And for that I need a defined current flow from the control to one side of the triac, which is one of the mains. If I would use a bridge rectifier, the voltage between ground and the mains line would jump from 0 to 250V depending on the mains phase. Another NO-GO.
Instead using the simple approach on the rectifying leaves the ground on the same level with one of the mains wires.
WARNING: Ground is directly connected to a mains wire. Touching Ground or any other connection composes a lethal danger.
As you see, only half of the sine is used by this simple rectifying method. This leaves us only with half the current over a full period. This will no longer be able to continously supply 35mA @ 3.3V for the ZigBee chip. But I won’t need it continously. Most of the time the CC2538 will be in sleep mode, awaking every now and then to send and receive commands.
You have seen that the capacitance C1 is the key to limit the current flowing through the cirquit. If this capacitance fails with a short, the full 250Vac will be routed through the cirquit and destroy it. C1 must be of a type that will fail as a open cirquit, so that if it will fail – and it will fail someday – it won’t take everything with it. Select a X2 type of capacitance here.
There are only few X2 types for surface mounting with a small footprint. 47n are about the limit right now. For higher capacitances and therefor currents I would need to use bulky through holes one. Phew!