It is a Really Bad Idea for hobbyists to work with household electricity, i.e. 110v in the USA, 240v in many other places. There is the chance that you will kill yourself or others. Also consider that if you only have a "little" problem, for instance you start a fire, you may find that your insurance is void, you may be sued for the damage you've caused. You may be prosecuted for illegal wiring.
Make a mistake with hobbyist electronics, running from safe-for-hobbyist sources of power, and you may fry some components. There are "things" you need to know about AC which you won't learn from surfing the web which can really "bite" you. Take for instance the concepts or AC, and "live" and "neutral". The moderately knowledgeable hobbyist would tell you that AC current alternates, first goes one way, then the other, and so it does. So why, then, if you connect a voltmeter between one of the wires in your household supply and the metal junction box it is housed in does the voltmeter read 110 (or 240) volts, but connect to the other wire and you see zero? (If you are curious about that, there's a discussion of household alternating current at MrFixit, but that's interesting academic stuff... not trade school training to equip you to fool around with 110 volts AC.) I've also written a page for you about the plugs and sockets used with household electricity. I've said a bit more there about "live" and "neutral".
One last safety concern, and then we'll get to how you can do it, if you feel inclined....
If you have a computer controlling something electric, be sure you are willing for it to be turned on automatically. I once had a computer controlled heater. One spring, as the days became warmer, I gradually forgot it was computer controlled. One day I realized that I'd draped a jacket over the heater, having forgotten it could be turned on by the computer. It was just a very happy coincidence that we didn't get a stretch of cold weather before I noticed.
Anyway... Want to use your own electronics to turn on "ordinary", 110 or 240 volt devices? There are safe ways.
Before I go into them, here's a design issue to consider....
Take something a simple as a light which you want to come on from 6pm to 10pm, to make your home look occupied when you are out. You can arrange something like that controlled by an Arduino or similar. You'll need something like an extension cord with a "switch" in it, a switch which can be controlled by the low voltages of an Arduinoor other is powered up, working properly. (A relay, perhaps.) But what about when the Arduino is not powered up? Will the light be on? Or off? If you create the "extension cord with switch", you can arrange things to work either way, and sometimes it will matter. In some of my "extension cords with switches", the switches are set up to be closed when the microcontroller input is absent... which makes the extension cords "ordinary" when I don't need to use them with microprocessor control. In addition, for some projects, such an "extension cord" gives me a more "fail-safe" result.
Something else novices may not know about: If you use a relay, you should have a diode. This is explained in my page about EMP snubbing diodes, which dissipate the reverse voltage spike which arises when the coil is de-energized. (I am going to mention some relay modules from Winford Engineering in a moment. From the online schematic for the modules, you can see they incorporate such a diode, along with an LED, in both their passive and TTL modules.
(See also, further down the page, solutions for 110 or 230.)
Sadly: now $27, 1/12 ($18.95, 6/11) +p&p)...
Also available... for $2 less... from PowerSwitchTail.com... and at 19 Jan 2012, Maker's Shed was showing the device as out of stock.
The PowerSwitch Tail is a very neat... in several senses of the word!... solution, which I commend to you... although the $6 price rise moves me closer to the camp which says the expense is to high for the risks it eliminates. But don't underestimate those risks. If in doubt, pay the small premium to be safe. After a fire, the $25 plus p&p would seem cheap.
Adapting text which used to be at the supplier's site...
You just connect one wire from the PowerSwitch Tail to the Arduino's ground, and another to a free I/O pin on the Arduino (or on almost any other micro-controller) and now you can safely control many standard 120VAC devices which connect to a standard 3-prong outlet. (i.e. NEMA 5-15R).
... and I don't dispute that... but... there's always a "but", isn't there?
Two quick things before we go into the "but"...
a) The PowerSwitch Tail uses an opto-islator in addition to other components, which is a bit of precaution I always welcome. This is certainly true of the version II, but was also true of the original, I believe.
b) The PowerSwitch Tail II is rated to control 15amps @ 125vac, resistive. (The original was rated 10amps @ 125vac, 3A @ 250vac, 5amps @ 30vdc, resistive.)
Happily, improvements to the PowerSwitch Tail in the second half of 2011 makes the "but" less significant. What they suggest should be safe in terms of you getting hurt by the household electricity involved, but an ill-advised but logical extension of the above would not be safe for your Arduino. Here's the detail: The Arduino site tells us that the maximum current though one of the output pins should not exceed 40mA. The Power tail site used to tell us that the control inputs for the PowerTail are "5DC volts nominal, 40 ma". Happily, the new (at 1/12) "PowerTail Switch II operates on 3-12 v DC (3-30ma). I was told that with a 5v control signal, the device draws about 10mA. (The device is clearly labelled- you'll see a "II", if you have the improved model)
So: with one PowerTail Switch II, wired the simple way, we are well below the Arduino's limits, assuming you aren't drawing a lot of power in other pins. However, suppose you wanted to control multiple PowerTail Switches with your Arduino? Not only should you keep the current through any one pin below 40mA, but there's another limit which you shouldn't exceed....
For the ATmega168, the limit for the total current through the package should be kept below 200mA. There's more at http://www.atmel.com/dyn/resources/prod_documents/doc2545.pdf, section 29. If you are using other outputs to source significant currents, you could exceed that. The improved PowerTail Switch is unlikely to be your prime culprit, but where-ever there is a big current draw, you could put transistors between the output and the current drain, and you would solve the power requirement problem.
The suppliers of the PowerSwitch Tail (see next paragraph) have, since at least 7/11, been selling a kit version of something similar... and the kit is available for switching 110v, or for switching 240v. Construction is not difficult, and the essential good enclosure is included. $18 + reasonable shipping at 7/11... and still that price 1/12. N.B.: You have to decide when you order whether you want to switch 110v or 240v... Although the kits are similar, the parts are different. Both the original kits (before about 1/12), and the PowerSwitch Tail Kit II U provide single pole switching at 20 amps, 5300vrms isolation. So! No excuses now, people on 240v... there is a reasonable way to switch mains voltages safely!
Another "either voltage" solution is offered by Winford Engineering of Bay City, Michigan. (The information in this section was harvested from the web in June 2011)
They offer relay modules with screw terminal connections, so you will need to arrange safe enclosures and safe connections to a plug (household electricity in) and socket (controlled household electricity out).
All of their modules are built around 15A SPDT relay... so, among other things, you can set one of these up to pass the household electricity through if the input from the microcontroller is absent, or only if it is present. Whichever you want.
Maybe I was just being dim, but it took me a while to work my way through the different options offered by Winford. Here's my attempt to set them out....
a) As it says on their site: "Please note that the relay coil voltage you select has no effect whatsoever on the voltages you can switch with the relay contacts."
b) Next choice: 2 relays per module or four? At 6/11, the 2 relay module (at 6/11 $33, only available in the "TTL" version... not a "problem".)
c) "TTL" or "Passive" version: The "TTL" version (aka "Logic Controlled") is essentially the "passive" version with a transistor. The control input goes to the base of the transistor. The voltage for the coil... 5, 12, 24 or 48... fed to the module separately... is switched on or off by the transistor. For most of the uses I would anticipate for the readers I would anticipate for this site, the "TTL" version is worth the slight extra you pay for it.
d) Coil voltage: The modules are supplied with relays requiring any one of 4 different coil voltages. Chose whatever is convenient, given what else you have on hand in your system. If you have a passive module, your input to it must supply the voltage the coil requires. If you have the TTL module, the voltage you apply to the control input can be from 2.7VDC up through 30VDC is fine, as long as adequate current is available. (The datasheet reports that the current needed is about 2mA if the input is at 5v.) Note: The coils are designed to operate off of DC supplies. I think it would be quite simple to tap into a 24v AC supply, as used in some home HVAC control circuits to produce an adequate 24v DC for the Winford modules, but my expertise isn't high enough for me to pass on my guess as to "the answer" to that want!
Prices (6/11, excl p&p)... the same for different coil voltage variants of each...
Passive: 4 relay module: $45
TTL: 2 relay module: $33 TTL: 4 relay module: $55
There's an excellent discussion of the above subjects, and related matters, on a page provide by www.YourDuino.com. There are also links from there to a source for some neat Arduino "toys".... but don't, like me, spend time looking for the "Ywrobot" relay. Just go to the YourDuino- associated store, or search eBay for "Wrobot" (no "y") relays!
Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org
....... P a g e . . . E n d s .....