Electronic – arduino – How to connect 230V 50Hz to arduino analog input


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 😉

Best Answer

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.