I'm wondering how practical (read: safe) it would be to use an audio capture device to "record" a mains AC signal for the purposes of monitoring the characteristics of the AC sine wave.

I am thinking something relatively simple like a feeding the live conductor through a resistive voltage divider and straight into the audio input. While this won't provide any isolation (but see below), I am assuming this will avoid any unwanted smoothing/filtering that could result from using a transformer to provide the isolation. However there is such a thing as a small 1:1 audio isolation transformer, but I'm not familiar with their behaviour - would they pass a 50/60 Hz sine wave of unknown quality without filtering it in any way? Obviously if it only passed through the 50/60Hz base frequency I wouldn't be able to see any distortion in the waveform so I imagine I will need something with a large enough bandwidth so as to allow any distortions to be accurately captured.

I would like to use a Raspberry Pi for the audio capture, mostly because it has an Ethernet connection for remotely streaming the waveform captures for display on a PC, but also because it has local storage to keep the captures in the event of a network interruption. Since it can be powered over the Ethernet connection and this also provides electrical isolation, I figure the solution with the resistive voltage divider isn't so bad because although the Pi itself would not be isolated from the mains, everything else would be. So long as the Pi is in a proper enclosure with the appropriate warning labels about it being mains referenced it should be fine...right?

My reasons for asking are that I am planning an off-grid set up and would like to experiment with using 3-phase motors as generators, so I would like to be able to continuously monitor the generated AC waveforms partly out of curiosity, and partly to have a way of identifying potential issues.

Being able to treat it as an audio recording also potentially allows me to capture say 24 hours worth of waveforms on a loop so that if anything goes wrong, I can look back and see what the power quality was like leading up to the event (e.g. frequency gradually dropping until it went out of range.)

There are devices you can buy that store waveform captures designed for power quality monitoring, but they are industrial devices and prohibitively expensive for hobbyists, so it would be great if I could accomplish the same thing myself with commodity parts.

  • 2
    \$\begingroup\$ An audio transformer will have a bandwidth into the many, many kHz, ideal for keeping all your line harmonics intact. Go with an audio transformer. Operate it within its Vs specification, so check very carefully what frequency the drive level is specified at. 1 kHz != 50 Hz. Do not even consider a direct connection to your pi unless its (a) battery powered or powered from the generator under test and (b) has a many kV opto-isolated link to the rest of your system, not just ethernet isolation. Ethernet isolation is only designed to break ground loops, not to keep you safe. \$\endgroup\$
    – Neil_UK
    Apr 17, 2021 at 7:43
  • 2
    \$\begingroup\$ Upvote for an excellently-written question. Lots of effort put into explanation, a great example to any new OPs. \$\endgroup\$
    – TonyM
    Apr 17, 2021 at 7:44
  • 2
    \$\begingroup\$ An audio transformer is unlikely to have mains isolation rating. Have a look at openenergymonitor.org to see how they're doing it. I also strongly advise against direct mains connection. \$\endgroup\$
    – Transistor
    Apr 17, 2021 at 7:48
  • 1
    \$\begingroup\$ @Neil_UK: Ethernet isolation (1500 V) is designed to protect equipment and people from dangerous wiring faults and induced transients. \$\endgroup\$
    – Dave Tweed
    Apr 17, 2021 at 10:49
  • 1
    \$\begingroup\$ @DKNguyen: Any "audio" interface is by default going to be able to handle the bipolar nature of the signal. \$\endgroup\$
    – Dave Tweed
    Apr 17, 2021 at 10:52

2 Answers 2


Most audio circuits have a low-end cutoff frequency in the 20 Hz range. So, even at 50/60 Hz, they will have a small attenuation, and a noticeable phase shift (perhaps 10-20 degrees).

Why do you care about the waveform so much ? The AC line is quite 'dirty' and most loads don't care. Motors and (incandescent) lamps don't care. Laptops, TVs, and other loads draw power proportional to the input waveform (power factor correction) and also don't care.

You are challenge is most likely to be large V spikes (to 1000's of V ?) and may damage your recorder.

  • \$\begingroup\$ My understanding is that devices with poor power factor (e.g. electronics) may draw power only on part of the sine wave, which can lead to increased vibration in the generator due to each rotation having uneven torque. Monitoring the shape of the sine wave is one way to identify this issue before it becomes a problem, and to also shut down the generator automatically if there is a risk of the vibrations getting bad enough that it could cause physical damage. The idea is to protect the generator rather than the load. \$\endgroup\$
    – Malvineous
    Apr 20, 2021 at 2:46
  • \$\begingroup\$ Well then you want to monitor the CURRENT consumed, not the voltage. With a reasonable generator, the voltage will remain sinusoidal, and if you have poor PF loads, the current will be distorted. Note that most modern electronics will have Power factor correction (PFC) and will draw sinusoidal current. Motors will have a phase-shifted current and only looking at the waveform will not tell you anything. Also, the distortion is during each cycle -- it won't cause noticeable vibration on the motor, \$\endgroup\$
    – jp314
    Apr 21, 2021 at 4:41
  • \$\begingroup\$ The current waveform won't be a problem as I can just use a current transformer, it's only the voltage I would still like to measure. Like I said in my question, partly it's just out of curiosity, and a conventional generator might be able to manage the voltage regulation but like I said I'm just planning to use a simple permanent-magnet motor as the generator, so I'm not sure it will have good voltage regulation, hence my interest in monitoring the waveforms so I can actually see what's going on and learn from it. A number of the devices I wish to use don't have PFC. \$\endgroup\$
    – Malvineous
    Apr 23, 2021 at 1:36

I have directly connected 120VAC mains to a voltage divider and directly digitized that and it works fine, although you really really do have to be careful about having energized neturals/grounds and stuff like that, which you seem to be aware of. Note that it is probably a good idea to put transient protection on one or both sides of the bridge if you want it to be connected for long periods, so think TVS on the high voltage side and zener diode on the low size.

Another potentially safer idea might be to use an opto isolator - either pre-packaged or home built. Basically use the mains voltage to drive an LED (possibly through a voltage divider) and then use a phototransistor to read the brightness of the LED from across an air gap. You might need two LEDs pointing in different directions if you want to see both sides of the waveform. Note that you will miss stuff very close to the zero cross because of the forward voltage of the LEDs, but you can add a bias if you need to see that stuff.

Quick and dirty that probably would work (and get me flamed on SE!): Connect an LED directly to mains with a suitable size current limiting resistor. Take a matching LED and point it at the first one and wrap them with some electrical tape to block outside light. Connect the leads from the second LED to the audio port. I bet the photoelectric effect on the second LED would be enough to be picked up by a 1V peak-to-peak audio port. If you can live with only seeing half the wave and having some clipping near the zero point, then you are done! Otherwise add another LED pair with reverse polarity and connect that to the other audio input (assuming it is stereo). You have some control over the gain and range by adjusting the current limiting resistor and size of the gap, and you can compensate for any non-linearity in software using Audactiy.

  • \$\begingroup\$ Very interesting idea using the opto-isolator! I presume I'd have to do some sort of calibration in case the output is not exactly linear compared to the input, or are opto-isolators designed to be used this way? \$\endgroup\$
    – Malvineous
    Apr 23, 2021 at 1:38
  • 1
    \$\begingroup\$ @Malvineous correct. This should not be too hard since you can calibrate the curve based on the voltage going into the LED after the divider and then backwardly calculate the corresponding mains voltages. A voltmeter and potentiometer (or variable voltage power supply) should be all you need. \$\endgroup\$
    – bigjosh
    Apr 23, 2021 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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