Electronic – Wiring a relay for mains power

relaywiring

I want to make a plug that I can turn on and off with a micro controller like a raspberry pi.

I picked up one of these http://www.radioshack.com/radioshack-15a-12vdc-125vac-relay/2750031.html
And the device I want to power is within the relays specs.
115 vac, 12 amps

I don't know how to wire it up, and I'm hopeful that someone has worked with these before

Best Answer

To say that the motor fits the relay specifications would need more than just the label. If it is fully compensated for its stalled start behaviour with the right start capacitor (that's still in good condition) it might be.

If it isn't compensated or not enough, or even over by a good margin, the relay may not last as long as you like.

Before you use this relay to switch any kind of mains voltage, please make sure it's new and has a clear stamp from a recognised testing institution (such as UL). I think with Radioshack chances should be good enough, but I have no personal experience.
The problem is that the middle pin, between the two pins that go to your Raspberry, is the centre contact of the switch. If the relay is badly made or you are not very careful you are effectively laying a mains wire extremely close to your logic 5V system. If they couple (physically or just through leakage) your entire Raspberry and everything it connects to may become "hot". So be weary and careful when hooking it up and make sure the relay looks good, new and reliable with some form of (international) approval.

That said, as I said the middle pin in the row of three is the middle contact. You can measure which one it makes contact with when the relay is off with a multimeter. Then use a 12V supply to turn on the coil (the outer 2 pins in the row of 3) and verify that the contact now connects with the other pin and no longer with the original one. That gives you your switch pin-out.

Then if you make this (while, again, taking care to insulate, insulate, insulate!):

schematic

simulate this circuit – Schematic created using CircuitLab

As you can see I made the mains phase the one on the switch over contact side, when the relay is off, that adds a teensy bit of extra safety, because the middle contact is not connected to phase any more. Of course only works as a trick if you are always 100% sure which the phase is.

The diode is to protect the transistor from switch-off transients.

The transistor can be any modern NPN type, or even an older BC550. Or you can replace it by a MOSFET like 2N7000 or 2N7002, but the 2N3904 is very well suited for the purpuse of relay switching up to 24V or even 48V (from memory it has 60VDC breakdown)/