Opto-isolated 240VAC Switching

A note on mains voltage: Mains voltages are DANGEROUS. This project should only be undertaken by people experienced (and preferably formally trained) to work with mains voltages. At the very least, have your work checked by a qualified electrician before plugging it in. The author can take no responsibility for injuries or death resulting from attempting to build the device described.


This project is to allow mains voltages to be switched from low-voltage signals such as Arduino Microcontrollers. I built these myself so that students in the DMC can switch such voltages with minimal risk to themselves. As such, these devices are presented to the students as a pre-built sealed unit. We strongly discourage unqualified people from touching mains-voltage circuits directly.

Note: This circuit will switch incandescent lighting loads fine, it has a bit of trickle current, so LED lighting will periodicaily flash breifly as the LED's charge circuit builds up a bit of voltage. For LED lighting I generally just run at low voltage and use switching transitors, like here.

Parts List

Main parts on display

  1. Aluminium project case (I used one that was 100mm x 50mm x 25mm - in hindsight a deeper one would have saved me having to bend the pins of the opto-switch).
  2. Locking cable gromets are used to hold the 240V cables securely and safely in the sides of the case. This is the safest way to do this.
  3. Some spare cable for the low-voltage connection between the spring connectors and the SSR.
  4. Short length of green earth wire with a lug on the end.
  5. 2 small self-tapping screws to attach the terminal unit to the case.
  6. Speaker wire spring terminals connect the low-voltage wiring. I could have used terminal blocks, but these are easier to use (no screwdriver needed) and anyone putting enough force on the control wire to pull it free needs a slap on the hand for trying to use electrical wire as a support cable anyway. Having the wires firmly connected but still easy to pull out under force is a safety bonus against trip-hazards.
  7. Solid-state relay (SSR). Taking a 3-32Volt DC input, this device can switch 240VAC@10A (resistive load, like lights -- I wouldn't switch an inductive load, like a motor, above about 2 amps off this device!). The low and high voltage sides are separated by opto isolation circuitry, which means a light beam inside the case carries the switching signal. This makes these devices very good for making sure the high voltage side stays away from the low voltage side as there is no electrical connection. The data-sheet for the one I used is here.
  8. 2 nuts+bolts to attach the SSR to the case.
  9. 2m extension cord (black, piggy-back plug).

I ordered items 1,2,6 and 7 above from commercial electronic supplier Element14. The extension cable was from a local shop. All other items and those below (not shown in image) are from my spares box.

  1. A few small rectangles of electrical-insulation plastic card.
  2. Short length of 4mm heat-shrink tube.


Starting with the case, I measured, centre-punched and drilled and filed out the holes I needed for cabling and screws.

The Aluminium case with holes cut out.

Next I soldered the connection wire to the spring-terminals, then threaded and shrunk heat-shrink tube over the solder joint and terminal pins to make sure there was no chance at all of a short to the case.

Wiring of the terminal connectors

I screwed the terminal unit into the side of the case and bolted the SSR to the base. Then I soldered the other ends of the terminal wires to the SSR. (As my case is a bit thin, I had to bend the SSR terminals over - carefully!).

First stage of wiring

Next I (very very carefully) ring-stripped the outer sheath off the middle 80mm of the 240V extension lead, not damaging the inner cable sheaths. I stripped a slot from the earth wire (green) and added a wire with a lug on the end. This lug is screwed under one of the nuts holding the SSR to the case. It provides an earth to the aluminium case, which is very important for safety - all user-accessible metal surfaces in high-voltage devices must be earthed in case of a fault.

I cut the active wire (the brown one) in two and soldered it across the switch terminals of the SSR.

Second stage of wiring

The neutral wire (blue) runs through the box untouched.

Mains wiring: In Australia and other developed countries, mains wiring has three wires. Check the wiring standards for your local region as the colours I use are for Australia and may not apply elsewhere! The three wires are as such: If all this talk of Active, Neutral, Earth, currents, AC, etc. is confusing to you - DO WORRY! You should not be working at mains voltages without a good understanding of this! You might consider paying an electrician to do the wiring for you.

Finally, I slipped some envelopes of folded electrical-insulator plastic over the terminals to stop electrical shorts to the case - the control lines shorting would be annoying, the active cable shorting would be potentially lethal! (I can't stress the danger of mains voltages enough, if you hadn't noticed. Being paranoid about electrical insulation is always a good thing). The Earth shorting to the case doesn't matter as it is connected to the case anyway.

Third stage of wiring

Threading the mains cable on the gromets and screwing down the lid finishes the electrics off. These are cable-locking grommets and while they certainly aren't an excuse to yank on the cables, they will hold it securely in place for normal wear-and-tear usage.


Finishing Up

I used Inkscape and GIMP to make a nice label for the front panel, which provides information on what the device does and how it is wired inside:

Case Label

The label is released public domain: you can modify/use it if you like (it is a 300dpi PNG image). I laser-printed it to photo-copier-safe plastic sticker sheet.

That looks nice and professional - I am quite proud of how it came out!



Before putting it anywhere near a mains voltage, I used a multimeter set to continuity indicator mode to check that there were no shorts between any of: Active in, Active out, Neutral, Earth, control positive, control negative.

Next, I took the device down to the university electrical engineering department for electrical certification (they have someone trained to certify things like this, and as well as being generally sensible, it is an insurance-liability requirement in the workplace).

With everything cleared, I plugged it into one of our photographic/stage lamps (300Watts in this case), and wired an Arduino micro-controller running the blink sample program into the control terminals. It worked as expected.

3 more to make (and get certed) should be enough to keep the students happy - they don't use mains stuff very often (I discourage it where low-voltage alternatives are reasonable) but it is good to have the option.


upBack to Glenn's Project page.