Transforming 120VAC mains power for Arduino input

This is an off-shoot from my first thread, but more generalized.

How do I transform my 120VAC mains power to the 5VDC power needed for an Arduino input? How do I know that I'm not supplying too many amps?

All I'm trying to do is figure out how to put up a dual-momentary wall switch that will act as an input to my Arduino.

Sorry for the noob questions :(

Not sure what kind of switch you are trying to read, so I may be off here. You can (mostly) safely throttle the AC voltage using a big honkin’ voltage divider. However, since AC cycles positive and negative, you’ll need something to bias it to all positive. Amps are not a concern (amps pull, volts push) unless you are trying to read the power. But you might want to isolate against power spikes.

Here’s one example of interfacing to an AC power line:

have fun, and be careful!

Get a DC power supply around 9 volts (just a cheap little "wall wart" or "AC adaptor" or whatever name they're called by). Make sure you have the polarity correct, and plug it into the external power jack on the Arduino. It should have around 500mA as a minimum, higher is okay for current because it's a limit of what can be supplied.

If you have a 5 volt, very well regulated supply that you're sure of and trust, you can connect it directly to the 5V line and ground on the shield connector.

So you want the wall switch to send an input signal to an arduino input or do you want to power an arduino from the wall switch ?


Sparkfun has a wonderful tutorial that I think will help you:


Looks like you want to use an AC power line as an input to the arduino?

Warning! Messing with AC power can kill you, someone who uses your device, burn your house down, etc. Do not screw with it if you do not know what you are doing.

If you not experienced working with AC power, I recommend you use a regulated 5V output wall-wart wired to the AC circuit you wish to sense, and use it to drive an arduino input pin. Use a pulldown resistor to keep it from floating.

Now that that’s out of the way, here’s one I have in use:

The connector on the left is for 120VAC-240VAC input. The PS2505L is an AC opto-isolator. The bleeder resistor is big, 1Mohm or thereabouts. Both resistors are standard 1/4 or 1/8 watt resistors. C1 must be rated for the AC voltage you’re using.

The arduino side looks like this:

P1 and P2 are connected to P3 and P4, respectively. TOOL1 is connected to an Arduino input pin. R3 is to protect from accidental bonehead shorts to Vcc, ground, etc. C5 is to reduce noise. D1 is an ESD protection diode since my application generates lots of static and the connectors could come in contact with it (wired to jacks/plugs, etc).

This circuit has been used with 240VAC and tested with 120VAC.