Table of Contents
Introduction
Sometimes there's a need or even curiosity to explore what the mains supply voltage looks like on a 'scope. I wanted to be able to do this in a safe way.
This blog post could be useful if there's ever a need to examine the voltage with (say) a multimeter or an oscilloscope, or even to chart or log the measurement over time, or examine any harmonics. It could also be useful for obtaining the 50/60 Hz timing (depending on region), or to connect to an alert if the supply fails.
The photo below shows the output for a nominal 240 V RMS mains input.
This project at a high level is simple, but I can't be held responsible if something goes wrong. I believe the project is safe, but no expert has assessed it, so you shouldn't assume it is faultless. If you have any corrections/improvements/tips, then please place them in the comments so that everyone, including myself, can benefit.
Circuit Diagram
The mains supply goes through a fast-blow fuse, and then it is used to supply a small current through four resistors and the primary of a current transformer, all in series. The output of the transformer is used to generate a voltage across a resistor, which is made available on a BNC connector (you could also use banana sockets if desired).
The output voltage will be approximately 1880 times lower than the input voltage, i.e. 240 V RMS will appear as 128 mV RMS and 120V RMS will be 64 mV RMS. If you prefer rounder numbers, then replace the 100-ohm resistor with two 47 ohm resistors in series, and then the output voltage will be 2000 times lower. 1% resistors would be a good option.
The ZMPT107-1 transformer (PDF datasheet) is available from AliExpress and from my measurements has a flat frequency response from at least 50 Hz to beyond 1 kHz (I didn't check beyond this range), so it is handy for observing mains harmonics levels too. The phase shift between input and output is about 2 degrees at 100 Hz, and about 20 degrees at 1 kHz.
Construction
I didn't create a custom PCB for this project, although it would benefit from that. Instead, the prototype uses single-sided copper-clad board; the copper was removed (I used a manual milling machine, it's a 15-minute job with that) leaving lots of clearance between the connections.
Extra holes were drilled for all off-board connections so that wires could be passed through them for some strain relief, or cable ties could be used to secure the wires further.
I placed everything to the left of the transformer onto one board, and the transformer and output resistor onto a separate board. This was so that it could fit more easily into the enclosure, and also it allows me to more easily swap out the transformer if I ever needed to.
The undersides of the boards are shown below.
The board undersides were covered with MG Chemicals 422C coating (a couple of coats) and dried off with a hot air tool.
The IEC connector hole was cut in the enclosure using a Dremel tool with cutting disc attachment. I used a Hammond 1591C enclosure.
I secured the IEC connector, and the BNC connector from rotating, with a small bit of superglue (the IEC connector has plastic tabs that prevent it from popping out, but it's better safe than sorry).
Thick wire (18 AWG) with a flame rating should be used for the connections to the IEC connector, so that the fuse blows in a fault condition, rather than the wire melting. Use a plastic enclosure with a flame rating. Stick a mains warning label inside the enclosure, or at least on the outside (or both). Don't omit the IEC connector, it makes the project safer than directly attaching mains cable to the box. The fuse is important too. Try to reduce the amount of naked connections just in case a user touches something.
Using it with a Multimeter or Oscilloscope
I connected a BNC-to-Banana-Plug cable to the device and attached a multimeter as shown in the earlier photo. The measured voltage was 0.128V where I am based (the mains voltage is 240V nominal).
By measuring the mains voltage directly and comparing the result, it was determined that the measurement needs to be multiplied by approximately 1900 in order to obtain the actual voltage of the mains supply, which is close to the calculated value.
Next, I swapped out the multimeter with an oscilloscope. The result is shown below. The flattened top and bottom is expected; the mains supply where I am based always has this shape. The 'scope measurements also show 0.128V, and the frequency was close to 50 Hz as expected too.
Capturing using an ADC
By connecting the tool to an ADC board, it is possible to log the data to a PC, for additional processing. A sound card would be one option. I used the MCC 172 card, it is possible for the Raspberry Pi to capture the data with great detail.
The chart below shows some captured data (see the MCC 172 RoadTest review to see how to capture the data; in brief, I installed and used the mcc-daq-tools on GitHub that were developed during the RoadTest, by typing the following on the Pi:
cd ~/development/daqproj/daqstream
./daqstream
The above daqstream
commands expose the data to other programs. I used Matlab. If you wish to use LabView, see Jan's RoadTest review for the MCC 172. Within Matlab, I typed the following to capture five seconds of data from the two channels that are on the MCC 172 board:
[c1 c2] = daqgrab(5);
The daqstream
and daqgrab
programs are on the GitHub site.
The above command captured five seconds of data to an array called c1
(The MCC 172 card has two inputs, but the second channel was unused and c2
is just an unused array containing 0V measurements).
It is possible to compute the RMS and THD values by typing in Matlab:
rms(c1)
thd(c1)
Here is the frequency domain view; I used Matlab's Signal Analyzer to auto-generate the commands for this, and then tweaked them to display the data in a friendly way:
Processing using Wave Miner
It's possible to connect the device to the Wave Miner which is a cheap Digital Signal Processor (DSP) board connected to a Raspberry Pi, to approximately measure the mains signal and to compute the distortion. The result won't be as accurate as using the MCC 172, but it's still useful if no more accurate tool is available.
I'll post the code to the Wave Miner GitHub page in the next few days. It computed the distortion in my case to be 2.5%, whereas the MCC 172 and Matlab measurement was 3.1%. The diagram below shows how the Wave Miner code works. It implements a ton of filters, all aligned to the harmonics, and basically measures the amplitude of the output for each filter. The Pi collects the results and computes the THD value.
Summary
This short project allows the user to be able to examine mains voltages in a hopefully safe way. Thanks for reading.