I want to use my arduino to make a simple mains power line voltage wave oscilloscope.
1. how to connect the mains power line (230V, 50Hz) to the arduino safely and efficient (I think a simple resistor voltage divider wouldn't cut it here)?
2. can i use serial communication to get this data in real time to the PC and then do some analysis in processing or some other software (maybe a simple labview analyzing the serial data because I'm familiar with this)?

any links for documentation would be highly appreciated, 10x guys ;)


2 Answers 2


It appears that you are not an electrician, so this requires a bit of a boilerplate:

Working with mains power should be performed according to your region's laws. It is dangerous and can seriously injure and kill you. Even the Earth wire is not at 0V with respect to the objects around you, due to unequal split-phase loading (or other more scary possibilities, like "That ain't the Earth wire, Jed! I just ran out of black!"). Please consult your local electrical codes before attempting to fiddle with it. Be careful using a cheap multimeter, as they are sometimes inappropriately labeled for CAT-II, III, and IV.

That said, there are two things that need to get done:

  1. Voltage transformation - the Arduino accepts only 0V to +5V or -5V to 5V, depending on type.
  2. Isolation - this is the safety bit, plus it'll save your parts.

Isolation : this is typically done using a transformer or optoisolators. While not technically achieving isolation, large resistors or capacitors (or a diode, but that is a story for another day) can serve if electrical code permits. Whichever is chosen, ensure they are rated for mains power in your region, the proper connectors are used, and care is taken near live circuits. I suggest a transformer followed by a voltage divider.

  • transformer

We all know what a transformer does. Since your aim is to measure instantaneous voltage, ensure that little distortion is introduced into the signal. This means it cannot come near (magnetic) saturation. The datasheets will have this information. Note that if you can characterize the distortion and it is a linear function (ie: not saturating the core), then you can account for this distortion in code with a simple LUT.

  • optoisolators

These are normally digital devices as they distort analog signals, but some are made for analag, like these ones. You'll want to look for a linear region in the output voltage vs. forward current graph. Again, if it is nearly linear, you can calibrate for it with a LUT. There is a catch, though: they're based on an LED, so they only work for a bit less than half of the waveform; it takes a bit of creativity to overcome this.

  • capacitor

A capacitor has impedance -j/wC. At 60Hz (or 50Hz, or 400Hz, or whatever it is) one can be used as a generalized impedance in a divider to limit the current throughput and generate a small voltage, but it does not provide isolation. This capacitor must be bipolar and rated for mains power use. A cap is also used for ac-coupling, discussed below.

  • resistive divider

This limits current and reduces voltage to safe levels, but does not provide isolation.

Voltage Transformation : All of the isolation methods except optoisolators produce bipolar outputs in various amplitudes. To map this +Vp/-Vp to +Vcc/-Vss, where -Vss may be GND, one can use either AC coupling or direct coupling. Direct coupling requires the use of a DC voltage source twice the peak voltage of your mains line, so that is scrapped. AC coupling requires a capacitor : alt text This can be improved in a number of ways but is likely sufficient. It requires isolation beforehand, and the capacitor can't be polarized or under-spec'd for the voltages it will support.

If I've mucked something up I'll fix it tomorrow as I'm tired and this answer is long.

  • \$\begingroup\$ great point with the transformer way of behaving, brings back memories form university. Long answers are better than shorter ones ;) 10x for the input ! waiting for your response tomorrow also ;) \$\endgroup\$
    – s.mihai
    Dec 11, 2010 at 11:16
  • \$\begingroup\$ Yikes, that's a bad circuit! You are essentially high pass filtering the AC line right into the micro. The AC line can have significant and large short term spikes on it. The high frequencies from these spikes feed directly into your A/D input without attenuation. These spikes can routinely be 10s of volts, and occasionally 100s of volts. Unless there is significant input protection in the ADC block you are not showing, the micro will likely get fried after a while. All it takes is a large motor turning off nearby, some switching in your substation, etc. \$\endgroup\$ Jul 7, 2011 at 12:56
  • \$\begingroup\$ Good point @Olin: a real circuit will include whatever is required for the real signal. I mean to demonstrate simple voltage transformation without distraction. \$\endgroup\$
    – tyblu
    Jul 7, 2011 at 18:48

What exactly do you want to see? Just the sine, or do you want to measure frequency or amplitude variations? Spikes maybe?

Anyway, you have a number of options:

  1. the simple resistor divider will do, if you can accept that your whole circuit is connected to the mains! You can't simply connect it to your PC that way, unless you can use an isolated EIA-232 connection.
  2. a small mains transformer. The secondary is isolated from mains, and the voltage level is closer to what you need. A transformer acts as a filter, however, so smaller spikes may not appear on the secondary side. You could use it for frequency or amplitude measurements however.
  3. A linear optocoupler, like Vishay's IL300. This one has excellent servo linearity of 0.01%. You'll need some extra circuitry though, see schematic below. The left side is connected to mains; the Vin is your mains voltage from a resistor divider. You can use a classic power supply with a transformer, or directly derive the power supply from mains.

enter image description here

Whatever solution you choose, make sure that you separate mains and arduino well enough. I don't know what standards are in the rest of the world, but here in Europe it's 6mm IIRC. This includes the distance between PCB pads both sides of the optocoupler! The trafo shouldn't give you problems here.

As for connecting to your PC through EIA-232, you can do so if your controller is not connected to mains (trafo or optocoupler solution). I'm afraid you'll may have to write your own software to display the waveform.

  • \$\begingroup\$ i want to see the sine wave 'with' spikes in order to calculate frequency and amplitude, as you mentioned using a transformer would filter this out. a resistor divider is the way to go from what i see (i took my multimeter apart and saw a R divider also) \$\endgroup\$
    – s.mihai
    Dec 11, 2010 at 11:12
  • 1
    \$\begingroup\$ Just to make sure you understand clearly: if you go for the resistor divider solution nothing in your arduino project is touch-safe! as it is connected to the mains voltage! \$\endgroup\$
    – stevenvh
    Dec 11, 2010 at 11:28
  • \$\begingroup\$ i mean voltage divider in order to connect the IL300 \$\endgroup\$
    – s.mihai
    Dec 11, 2010 at 12:49
  • \$\begingroup\$ for U1 and U2 what would you recommand i use ? (i always have a hard time picking components due to the noobiness and full A4 page of characteristics) \$\endgroup\$
    – s.mihai
    Dec 11, 2010 at 12:49
  • 1
    \$\begingroup\$ The datasheet for the TLC271 is only 81 pages, so what are you complaining about? :-) BTW, the TLC271 may be a good choice: it's not the cheapest but neither too expensive, it runs from a single supply, doesn't need much power and has a high impedance input (so your voltage divider will not be loaded). But others may suggest other types (which may make the choice even harder :-( ) \$\endgroup\$
    – stevenvh
    Dec 11, 2010 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.