Mains switching is something I've always wandered about; relays always seemed like the way to do things, but what if you don't have a device that can supply enough current to throw the switch, or what if space is quite a limiting factor?
I looked into triacs to solve my problem, and, with my new found knowledge, I set about creating the circuit detailed below:
The MOC3020M is a triac optoisolator - basically, it's a light-sensitive triac with a small light source in one component. Pins 1 and 2 are used to turn the light source on and off, which in turn allows the internal traic (pins 4 and 6) to conduct. This internal triac is used to trigger another traic; one which is capable of dealing with larger currents. Mine, the 2N6073A, could handle 4A if heat-sunk properly. But, I've kept it well away from that with a 2.2A circuit breaker.
There's a fair amount of information on the Internet about how traics work, so I won't put any here; take a look if you're interested. Basically, the triac will conduct (through the main terminals) as long as there is a voltage/current on the 'gate'. It stops conducting, after the gate voltage/current has been removed, as soon as the voltage/current over the main terminals crosses zero.
I decided to put my circuit in a small plastic box to keep it safe and out of the way. I also attached a trailing socket so I could use it for more than one project, easily. The earth wire isn't connected in my circuit (except to the trailing socket) since the box is plastic. For the control cable, I decided to use a length of telephone cable (which normally has RJ11 connectors on the end) using just 2 of the strands - leaving room for expansion.
The mains device can be triggered 'on' by applying 5V to pin 1 of the triac optoisolator. My intention was to have the circuit triggered by my Arduino, opening a world of possibilities.
One thing I have noticed with my circuit is that when certain devices at home are turned on, but the triacs are off, the connected device (to the trailing socket) gets a bit of power for a fraction of a second. The traic miss-fires for a tiny period of time due to the magnitude of dv/dt - the change in voltage per small unit of time. These values are discussed on the triac's datasheet. If this becomes an issue, I'll have to design a snubber circuit to dampen the effect and solder it in (hence the large space to the left of the board).
Words of warning: Mains electricity is very dangerous; do not do anything like this if you're not sure what your doing. I did a fair amount of research before building my circuit. The components in this circuit can become damaged from transient voltage spikes so I'd advise against using inductive loads with this circuit - the triacs may fuse open (or worse!). Stick with resistive loads!