Introduction: Safely Controlling Mains Powerline Sockets Using Electronics
I wanted to control some mains equipment remotely using an electronic circuit, but did not want the hassle of sending signals through the power line or via a serial radio link, etc. The circuit had to be safe.
This project uses a low-cost mains-socket remote controller and its associated 13A plug/socket. The (battery powered) handset is hacked to be controlled by an electronic circuit and the 230V mains socket is never touched - hence a safe way of using electronics to control a mains-powered device.
I chose to use a PIC microcontroller to monitor a light-dependent-resistor. When the light level is bright, the mains socket is switched on, and vice-versa.
(The LDR could monitor the screen of a mobile phone to produce a mains socket controlled via the mobile phone system - see the last step in this Instructable.)
The original system controlled four mains sockets and could also act as a dimmer. All of these functions could be retained, I only wanted one channel, although the hack is ready to control three mains sockets if I ever need more in the future.
Step 1: Inspect the Remote Controller
The remote system I hacked had been purchased in Lidl and had four 13A sockets (one of which had failed). There are many similar sets, I guess they could all be adjusted in a similar way. One of the benefits of this project, is that it is still fully operational for its intended use, should I ever need to use it again.
Open up the remote controller and extract the circuit board. Mine had 12 buttons. Perhaps the hardest part of the project was to see how they were connected and draw out a circuit.
Step 2: Work Out How the Switches Are Connected
Needs a little patience!
I wanted to make connections to the PCB so that I could duplicate the action of the manual switches. I needed to reverse-engineer the connections for the switches and solder wires onto the PCB which I could operate externally.
I started by drawing circles on a piece of paper to mimic the layout of the PCB switches.
I added switches inside the circles to show the orientation of the two half-pads.
I then carefully inspected the PCB layout to copy how the pads were connected together. The switches form a matrix with one end connected to the integrated circuit (the black blob visible towards the right hand side of the PCB).
I only wanted to control six of the switches (on and off for three 13A sockets) so I didn't do all of the switches.
It transpired that I needed six connecting wires, to bring out the connections to the switches. Yes, there are 12 contacts for six switches, but several wires are shared. On my 'real' circuit diagram (see the fourth photo) I labelled each of the six connecting wires which I was going to add (and put a circle round them). To switch Socket 1 OFF, I had to connect wires 1 and 2 together. To switch Socket 1 ON, I had to connect wires 1 and 4 together. Etc
Step 3: Make the Connections to the Switch Pads
You could solder 12 wires directly onto each side of the six switches and all would be fine. However, this would have to be done on the tracks-side of the PCB and the buttons could then not be used. This would stop the remote control from being used in its original way.
I chose to work on the other side of the PCB and find suitable connecting points to gain access to the six connections I needed. There were suitable links and holes already in the PCB, so I did not have to do any drilling.
I had some very fine enamelled wire which helped some of the connections, otherwise I just used ordinary insulated connecting wire.
The photos show the work in progress and the final socket.
Step 4: Add a Neat Socket to the Remote Controller.
The final part of the modification was to add a socket onto the side of the remote controller and connect my six wires onto it.
I super-glued the six-way SIL socket onto the PCB. This has held well - otherwise I would have used hot-glue to reinforce the socket.
I cut a slot in the side of the case so that I could put it all back together.
The added wires and socket do not affect the operation of the remote controller. It still has its battery inside and works fine!
Step 5: Testing the Hacked Remote Controller
I knew which of the socket's connections I needed to join together to mimic the operation of the six switches, so I did a simple test.
I plugged in a 13A mains socket, used the remote to 'train' it to be Socket number 1, then shorted pins 1 and 2 on the 6-way SIL socket which I had added to the remote control. The mains switch operated fine. All the other connections worked fine as well.
(Please note, the shorting is done on the added connector on the battery powered, remote control - NOT on the 13A mains socket!!)
Step 6: The Electronics - How to Control the Remote's Switches
I wanted to use a PIC micro controller to operate the remote, but was nervous about voltage levels in the hacked remote (the remote used a 9V battery, a 3V voltage controller for its keyboard PCB and a 5V supply for its transmitter).
I could have used relays, etc. Much simpler is a great integrated circuit which has inbuilt (isolated) analogue switches, controlled by pins connected to digital signals. The CMOS chip CD4066 is shown. I only needed two of its switches to operate an ON and an OFF.
It is easy to test on a breadboard. It worked perfectly.
Step 7: Design a Circuit
I like microchip PICs. I tend to concentrate on using one variety (16F88), which is hugely over specified for this purpose; but it only costs £2 or so, and I have a few around - when this circuit is of no further use to me, I can re-use the PIC (I always use PCB sockets).
I always produce printed circuit boards for my projects and I use KiCad for the schematic and PCB design. Its slightly idiosyncratic in the way it operates, but it works well, has unlimited functions and is free! I have used Eagle, and it was great; but the free version has a limited board size.
KiCad has a brilliant, instant 3D modelling view, which permits you to 'fly' around your board. Not every component is modelled, but it is a great visualisation of what you are about to produce. Two screen shots are presented here.
I program the PIC in GC Basic - another free offering which is really well supported by its developers and brilliantly easy to use. My days of struggling with OP Codes are over (although they can be seamlessly incorporated into GC Basic programs).
I always include an LED in my projects, even if it is not 'needed'. I usually pulse it for a second or two as the first thing the program does. This tells me that the software is running. If the program is doing some action, I normal flash the LED simultaneously for a short burst to let me know that the program is operating.
I often include a 3 pin SIL plug with a link (which shorts two of the pins together). The centre pin is connected to one of the PIC's in/out ports, the outer pins are connected to 0V and +5V. This plug serves two purposes; firstly with the link high, the software will perform some test routine (eg flashing the LED, repeatedly operating the ON then OFF buttons, driving a motor, etc) with the link low, the software will run the 'proper' operating program. Secondly, the three pins enable me to piggy-back on an extra sensor or output device which I had not thought about, or which became necessary after producing the PCB for some reason.
I usually connect the power via a tiny 2 pin SIL plug. I have a 2 pin SIL socket wired to two 4mm plugs which go into my bench power supply. I use this during development (it has a current limiter which has saved me from a smoking circuit on occasion). The finished project has a battery connected to a similar socket.
Here, the software is simple. Every minute, the LDR is checked. If it is below a threshold the OFF button is operated on the handset. If it is above the threshold, the ON button is operated. The buttons are only operated if the light level has CHANGED across the threshold - this stops the ON button (say) from being repeatedly operated every minute when the light level is high.
PICs can be put to 'sleep' (drawing a few microamps) when nothing is happening, so a circuit like this barely runs down the battery. To let this happen properly, the high end of the potential divider (which has the LDR and the variable resistor in) is not connected to the +5V (which would draw current all of the time), but is only pulsed high when the LDR is being read by the software (a settling time of 0.2 seconds is applied before reading the A to D port to allow for the slow response of the LDR).
Step 8: Produce the Circuit Board
I follow the 'usual' photographic method for producing PCBs. That is:
Print out the copper trace on paper. (1 minute)
Use photo-sensitive single-sided PCB board.
Use an ultraviolet light box to expose the PCB board. (3 minutes)
Develop the board to expose the unwanted copper areas. (5 minutes)
Etch the board. (15 minutes)
Drill the component holes. (15 minutes)
Clean the PCB with emery paper and give the copper a wipe with flux. (2 minutes)
Solder on the components. (30 minutes)
A few notes:
The whole process is pretty quick, once you have it sorted. It took about 2 hours - more if you have to mix chemicals and find components, etc.
I use an ordinary laser printer and some 'special' PCB film (like tracing paper). When the 'special' paper is gone, I will try ordinary tracing paper instead!
I put the etchant in a hot water bath (filled from a boiling kettle). This speeds up the process. I use Sodium Persulphate as an etchant. Less messy than ferric chloride, but a little slower. The main benefit is that it is basically transparent so you can see how the etching is doing. It steadily gets bluer as you re-use it. It doesn't stain you, or anything else.
I made my own UV exposure box (using an Ikea, glass-fronted display box as a basis). I also made my own PCB drill stand. The photos show these.
Step 9: Putting It All Together
The device works well. The LDR senses the light level and operates the ON button of the remote when the light level is above a threshold (adjustable with the variable resistor on my PCB). If it falls below the threshold, the OFF button is operated. The associated 13A socket operates perfectly.
The software loops around every minute, checking the light level. It also keeps track of the state of the socket, and only triggers one of the buttons if the state of the light level represents a CHANGE. Without this, the button would be operated every minute, which would make the handset's battery run down rapidly.
Mobile Phone operated remote control
Keep your eyes out for another Instructable which will be based on this. The LDR will monitor the screen of an old Nokia 3210 mobile phone. If the phone receives a call, the screen will light up and the mains switch will operate. Perhaps two calls in one minute to switch on the socket and one solitary call to switch it off. The phone will not 'pick-up', so this will produce a remote control mains switch operated via the phone system.