A convenient adapter to view the electrical grid waveform through your PC's sound card.

Public Chat
Similar projects worth following
There is a lot to be observed from the waveform of the electrical mains. Harmonics, transient changes, periodic fluctuations, frequency shifts, impedance, power line communications - These all give clues as to the state of the country's electrical transmission system (or what loads your neighbour has connected). Platforms like MATLAB allow for the easy analysis of waveforms through powerful software tools, but only once the signal has been acquired.

The purpose of this project is to allow easy and safe access to the electrical grid waveform without a hassle. It's as simple as power cable in and 3.5mm audio out.

Current status (17th Sept):

-->Final enclosure has been 3D printed.
-->Parts are here (both digikey and element14 orders).
-->Software to be used will be a combination of MATLAB for processing and SpecLab for "listening" and possible pre-processing. See SpecLab here:
-->The new V2 PCBs are at my parent's house, but they currently are sick from the flu. I can't risk passing any sickness onto my pregnant wife so I'll have to wait.

Current focus:

-->On hold until October! I could start the software now, but I very much prefer to have the actual hardware working first.

The Grid-2-Audio module is comprised of three main parts:

1. The case and IEC all-in-one power entry connector - As part of teaching myself AutoDesk Inventor, I decided to start with the mechanical aspect of the project. The presence of mains voltage potential is no joke and the design of the case reflects that. The utilisation of an IEC power socket with built in switching, fusing and illumination minimises any mains wiring around the internal space of the unit.

2. The PCB power supply and mains input - As the unit is design to measure the grid voltage and introduce minimal noise, the power supply needs to ideally draw a minimal sinusoidal current (at the fundamental frequency) in phase with the voltage. Additionally, there needs to be isolation between the mains measurement circuit and the output side, forcing the requirement of multiple transformer taps for the whole PCB.

3. The PCB signal conditioning - The mains signal needs to be conditioned to the 3.5mm audio format and protected from shorts. As an extra feature, a 50Hz high-pass filter will be included to provide an alternate "harmonic only" output to increase the dynamic range for harmonic analysis. EDIT - The filter has since been removed and will now be accomplished via software libraries within MATLAB, etc.

Here is a picture of the hardware waiting for the new PCB and assembly:

Late update:

Brian was kind enough to write about this project on the main page some time back:

There were some interesting ideas in the comments about retrieving isolated signals, but what I certainly took to heart was the emphasis on isolation distances. Although I couldn't achieve 6mm clearance (I increased it to 5mm), I added slots (for extra creepage) and increased the mains voltage divider resistance values to only allow a "2mA shock" if the isolation AND earth fail.


Design files for the entire schematic/layout.

RAR Archive - 1.14 MB - 09/08/2018 at 04:01



Gerber files for the design. Note that this rar can be directly uploaded to gerber viewers and previewed/manufactured. The top/bottom paste layers are not included (can be generated from the Altium files though).

RAR Archive - 38.61 kB - 09/08/2018 at 03:59


PCB 3D Models.rar

3D models of the PCB design (Step, STL & PDF).

RAR Archive - 1.46 MB - 09/08/2018 at 03:57



3D models of the three parts of the device enclosure (Step & STL).

RAR Archive - 1.59 MB - 09/08/2018 at 03:57


BOM Grid-2-Audio.xlsx

A bill-of-materials list for the components to be loaded onto the PCB.

sheet - 11.72 kB - 09/08/2018 at 03:54


View all 6 files

View all 13 components

  • Ray Tracing In Autodesk Inventor!

    David Scholten09/11/2018 at 11:07 0 comments

    Just as a distraction, I found the ray tracing button in Autodesk Inventor and decided to abuse it:

    And of course I just had to for comparisons sake:

    I had way too much fun making these ray tracing renders! They did take 20-40 minutes each with 100% CPU usage though...

    (Not sponsored by Nvidia).

    Make sure to check out the project log just before this one as I uploaded two at once.

  • Version 1.0 --> to 2.0 Changes and File Uploads

    David Scholten09/11/2018 at 10:46 0 comments

    So first of all, all of the design files have been uploaded (well, the newest versions anyway) and are available for download. The original intention of this project was to make a nifty little product and sell them on eBay. However, due to some bad economic decisions with the component selections, I can't see the grid-2-audio unit being profitable in small batch production. As a result (and to Hackaday's liking) I'll just upload all of the design files here for anyone with a non-commercialisation intent.

    Summary of 1.0-->2.0 PCB changes:

    Number 1: Safety! The obvious safety concerns were the clearance from the mains potential to earth and the short-circuit shock capability of the mains measurement circuit should it be touched/connected.

    -->There are two dangerous regions: The mains active/neutral region (lethal) and the signal processing region that is referenced to the mains (current limited during shocks). The voltage divider across the mains has been increased from 60kOhms to 240kOhms. Based on the arrangements the practical shock hazard of this region has now dropped from a ~7-8mA shock to a ~2mA shock. This is no longer dangerous even if a person were to experience it (it still hurts). Increasing the resistance of the mains voltage divider sounds like it would introduce noise, however this is not the case as the actual voltage difference is measured across 2kOhms. The divider acts like a 2kOhms in parallel with 240kOhms to the following op amp and so any noise is effectively dampened. However, that 2kOhm resistance is at the limit of what the opa2134 op amp can tolerate before another circuit is recommended by the datasheet (not to mention the op amp’s input capacitance starts to affect the upper frequency bands at 2kOhm).

    -->The minimum clearance between the earthed section of the circuit and the hazardous regions of the design was increased from 2mm to 5mm. This certainly is clearance enough from the "2mA shock" region, but I also added some 2mm cutouts in a region where the active connection comes within 7mm of the safety earth. Cutouts were also added throughout most of the isolation region just for the sake of good practice to maximise the creepage distance where ever possible:

    Number 2: Footprints…

    -->The 3.5mm headphone jack footprint that I downloaded did NOT have slotted cutouts! Although the 3D model did and the footprint pads were elliptical, I missed this completely. This has since been corrected.

    -->Fixed all of the 100nF bypass cap issues with gerber viewers. Although the final V1.0 PCB turned out okay, the manufacturer’s gerber viewer wouldn’t display the 100nF pads at all (only the top solder cutout for the pad). I simply went into the footprint and deleted/recreated every piece of geometry and it fixed the problem?!?

    Number 3: Stupid mistake.

    -->This is a good one. I connected ground of the 3.5mm audio jack to the output signal and vice-versa. I’m glad I caught this because it’s the kind of mistake you can live with (using an adaptor cable) and be reminded about constantly for the rest of your life.




    Right, now with that out of the way I present the “final” schematics/layout pictures, which are ALL available in the project files directory in Altium form:

  • Very Accurate PCB Fabrication/Assembly

    David Scholten09/08/2018 at 02:55 0 comments

    The new boards arrived and assembly is complete:

    Project complete.

  • Goodies from the Internet

    David Scholten09/06/2018 at 02:39 0 comments

    Although, yes, the first version of the PCBs had design issues and are not usable (notice J3 is NOT slotted), they arrived in good order and seem to be quite alright. Here is version 1.0 at last:

    Labelling the entire bill-of-materials for the PCB did take some time though (transformers not shown):

    As the PCBs are so cheap compared with a set of components, I will certainly not be soldering together V1.0 and instead opted for express shipping for V2.0 of the PCB (ordered on the 2nd Sept.).

    I did have fun preparing and decorating the enclosure parts though:

    Though I'm still having trouble choosing between the red and orange face plates...

    Project status:

    Sorry for the small update, a larger one is coming soon that will include an upload of all of the CAD files to allow others to do whatever they like with them (short of commercial use). Additionally, there will be a more detailed explanation of the v1.0-->V2.0 changes as well as an upload "final" schematic project photos.

  • Cya Later Prototypes Cases!

    David Scholten08/14/2018 at 12:58 0 comments

    It's been quite the 3d printing adventure, but it's time for the pieces of prototype cases to finally go in the bin (save for the few nice looking ones at the bottom):

  • The End of the Design Phase!

    David Scholten08/06/2018 at 06:42 0 comments

    So here's the latest update!

    After a break from the project, I've had some time to finalise all of the minor aspects of the PCB layout (connectors, spacing, physical dimensions, etc.) It took an entire day, but putting it off would have taken an entire month.

    This is, without a doubt, the final high-level circuit diagram:

    The final layout:

    I did have some concern about the spacing between the "7mA Shock" section and the "safe" section, which is only separated by 2.5mm at the closest point. I was under the assumption that 7mA through the human hand to ground was merely painful, but it seems to start to encroach in the "cannot let go" territory. As a precaution, I've made a few circuit modifications to allow a sensing resistor configuration that will only allow a current of 3-4mA (max) through the human body should something go wrong (60kOhm inline resistance). However, for this to possibly occur, four things would have to happen:
    -->The 2.5mm isolation is breached.
    -->Earth comes loose within the unit.
    -->The connected 3.5mm device also has an unearthed ground.
    -->The person has conductive hands, etc.
    Although unlikely, this is still concerning, especially if I were to give/sell a unit to someone else.

    Regardless, back to snappys:

    The idea behind the white silkscreen section at the top and the terminal blocks up there is that in this way an IEC quick connect panel mount connector can be used at the end of the case to make the PCB into a single unit (as originally intended). However, this also allows the PCB to be removed from the 3D printed case and used as a separate mains-->audio PCB as part of a bigger unit (with terminal block input/output). This is also the reason for the terminal block next to the headphone jack, which cannot be normally accessed whilst inside the 3D printed case.

    To incorporate the finalised PCB into the old case, the 3D printed design needs to be enlarged by about 60%.
    Below can be seen an enlarged version of the primary case extrusion:

    However, since we're 3D printing and not actually extruding aluminium, the case body can vary in width along its length! The base of the case has a smaller opening to allow the existing IEC connector to retain compatibility:

    The same size expansion has been applied to the front and back panels as well, though the face decorations/labels are yet to be determined:

    Here's a quick picture from a failed print to preview the size compared with the old case:

    I'm really feeling the project fatigue now. I've been dedicating mind-space to this project for months now and there are so many other things I want to do! Having a "properly" done PCB design and case is nice an all, but the gimmick wares off VERY quickly. This project should be called "An exercise in engineering design: tolerance and perseverance" or something along those lines. I just want to breadboard sparkly things...

    Anyway, the next step now is to print all of the cases to a satisfactory standard and make an order for the PCBs/components. Ideally everything will fit and the PCB will work fantastically the first time it's powered on.

    I'm sure this will be the case...

  • PCB Layout

    David Scholten07/13/2018 at 01:15 0 comments

    As promised, here is the PCB layout of the Grid-2-Audio module (minus the I/O connectors).

    Top view:

    Bottom view:

    2D view:

    The general philosophy was to divide the board up into three sections, each with an escalating level of danger. The first is the mains section, which exists solely to power the transformers and take a voltage divider. The second is the non-isolated side of the ISO124, which is powered by one of the two transformers and has a 30kOhm connection to active (about a 7mA shock potential). The third section is the isolated side of the ISO124 that is powered by the other of the two transformers. This side is effectively galvanically isolated, physically separated and earthed (earthing is not yet shown in the images).

    My only concern at this point is the heat dissipation on the mains side resistive divider and the earthing circulation currents that may degrade the output signal (unlikely).

    The next step is to touch up the layout a little bit and get to work on modifying the enclosure to fit the now-larger PCB.

  • Schematic Modifications - Final Revision

    David Scholten07/12/2018 at 07:21 0 comments

    Sorry it's been a while, the project is still underway!

    Aside from the input/output connectors, the schematic is completely finished (I know this is true this time because the layout is almost finished).

    The schematic overview remains the same (minus a couple of mistakes with the power orientation):

    The power supplies are also unchanged (but now the wires are actually connecting and not maintaining an illusion):

    The grid measurement section now contains a new input filtering capacitor (30MHz crossover):

    Now, onto the actual changes... The most notable change is that the signal processing portion of the circuit has been significantly simplified to eliminate the 500Hz harmonic filter. 

    The original intention of this filter was to increase the dynamic range of the harmonic measurements as the available audio range is about +/- 450mV. If the harmonics are only a small portion of the 50Hz fundamental waveform, they will be at the mercy of the sound card's sampling accuracy. The secondary "harmonics only" output would eliminate the 50Hz fundamental component and allow amplification of the harmonics without the 50Hz clipping. This would then be fed to the sound card as a +/- 450mV signal to increase the dynamic range.

    However, I eventually decided against this as the filter's response wasn't completely flat - Especially in the more interesting 500Hz-2kHz (10th-40th harmonics) range. Not to mention the sub-500Hz is completely gone (2nd-9th harmonic). It all seemed a bit pointless in the end.

    The other change is the removal of the DC-offset removal capacitors from the op-amp U5. As the gain at this stage is 0.129 (as opposed to a value over 1.0), the DC offest from the previous stage (the ISO124's massive 20mV) is reduced to 2.57mV. As the OPA2134 will add not much more than 1-2mV, the final DC-offset will be around 5mV max in most circumstances. This is about 1% of the signal peak, which is reasonable considering sound cards block DC voltages anyway.

    Now, taking these changes into account (and the existing design) the final frequency response is flat from 0Hz-20kHz and then decays from after that until about 50kHz where it drops off rapidly.

    Stay tuned for the layout pics!

  • Schematics are Done!

    David Scholten05/30/2018 at 12:08 0 comments

    Finally, after weeks of umming and arrring, the schematic is done!

    The overall design of the system has remained unchanged with the exception of the input filter. Originally, there were plans for an input LC low pass filter to reduce the harmonics and fluctuations in the mains supply current, which would result in measured voltage harmonics in the system. This is due to the resistance of the input IEC cable. Here is the final system hierarchy with the LC filter removed:

     To compensate for the lack of input filtering, the power supplies have been modified to include a series resistor to limit the 100Hz “inrush” current to the electrolytic capacitor. Each half cycle there is a rush to “refill” the capacitor, which results in a sudden impulse of current. The series resistor limits this current and dramatically increases the charge time of the capacitor. This thereby reduces the peak current and the voltage harmonics due to the IEC cabling resistance. However, this does reduce the minimum capacitor voltage and the transformer turns ratio has been adjusted to compensate.

    The mains current before the series resistor is added:  

    After the resistor is added:  

    Other than this factor, the power supplies (+/-9V x2) are quite basic and remain mostly unchanged:

    The signal acquisition block of the hierarchy takes the grid voltage and produces a safe, isolated, 4V copy to send on to the signal processing block:

    First, the voltage dividers reduce the mains level down to the 4V level. Using such large value resistors (power dissipation limits) has the potential to introduce thermal noise at this point, so the thick film type resistors were used to alleviate the issue. The 4V signal is then buffered by an OPA2134 op-amp and fed to the ISO124 isolation amplifier (lower input impedance), which provides near-galvanic levels of isolation. One of the many drawbacks to the ISO124 is the practical requirement for 4 separate power supplies (two of which are isolated from the other two) to drive it. Additionally, the ISO124 leaves the signal with a 20mV (0.5%) DC offset, a very low current driving capability (<10mA) and a 10mV (0.25%) 50kHz ripple.

    Signal processing time (some resistors and caps have not been selected):

    The signal processing hierarchical block takes the 4V signal and applies a 2nd order low pass filter that works in conjunction with the internals of the ISO124 to produce a 3rd low pass filter to remove the 50khz ripple. This signal is then sent to an inverting amplifier to reduce the signal magnitude to about 450mV peak and provide increased current drive capability. In addition, this op amp also removes the DC offsets that have accumulated and removes any RF interference/noise (1.5MHz 3dB point).

    The 4V signal is also sent to a 3rd order high pass filter for a harmonics only output (500Hz+). After this the harmonics-only output is sent to another op amp to increase the signal magnitude to a matching 450mV peak output (along with DC offset removal and RF reduction).

    The final outputs are/will be scaled (approximately) such that:

    Main output: 0-450mVp is 0-423Vp (50Hz to 20kHz)

    Harmonics output: 0-450mVp is 0-20Vp (500Hz to 20kHz)

    The frequency range does expand up to 50kHz (-3db), but it only remains flat until about 30kHz. As sounds cards (mostly) cap before 20kHz, I only concerned myself with the bandwidth under 20kHz during the design process.

     Sorry for the incoherence throughout the post - It was written quickly in many chunks ;)

  • It's the Little Things...

    David Scholten05/05/2018 at 12:13 0 comments

    Still working away at it in my spare time, but a lot of small things are catching me out.

    The latest is the ISO124, a 21 year old IC, with extended requirements for bypassing and output filtering:

    It's not that it's difficult to implement, but the assumption that it this sort of IC conditioning wouldn't be necessary is what now requires me to rework some of the design.

    This IC also makes all of its electrical claims with only a 2kohm load - Do I need this?! Can I buffer the output and improve the specs - Or does it make them worse?! I'm not going to make more assumptions. Working backwards from examples gives clues, but it is frustrating.

    The 2k load then has a cascading effect on the power budget and so on, which is causing continual annoyances.

    More to come soon.

View all 14 project logs

Enjoy this project?



David Scholten wrote 09/06/2018 at 01:26 point

Orders for the PCBs V2 are away as of the 2nd September! Some critical changes to footprints and safety warranted a new revision. The total cost for 10 unloaded boards was about $30 (including express DHL shipping) from Seeed Fusion (posted to Australia).

  Are you sure? yes | no

chibill wrote 08/23/2018 at 21:26 point

Would this work properly on 60Hz 120V American Power lines? Or would some parts have to be slightly changed?

  Are you sure? yes | no

David Scholten wrote 08/24/2018 at 00:00 point

Hi Chibill, to adapt it to 60Hz/120V you would need to to replace the two transformers:

with equivalent 60Hz/120V variants.

Additionally you would need to remove one of the divider resistors and change the tiny input filtering capacitor that is in parallel with that same resistor (or just remove it, I doubt it will have much of an effect).

Once I have the PCBs/parts and I can test the design I'll upload the CAD files along with regional variations (if I can find alternate transformers in the same footprints).

  Are you sure? yes | no

chibill wrote 08/24/2018 at 00:31 point

okay. Sort of figured the transformers would have to be replaced. (As that would lower the voltage on the inside of the device if it wasn't changed)

  Are you sure? yes | no

David Scholten wrote 08/15/2018 at 12:54 point

Orders for the components are away as well! The total cost shared between Element14 and Digikey (including shipping and everything) was $137AUD. I did over-order on a fair few parts to provide a few likely spares though.

I'd rate that new sub-$1000 Australian GST tax a solid 3/10. Ouch.

  Are you sure? yes | no

David Scholten wrote 08/11/2018 at 02:10 point

Orders for the PCBs are away! The total cost for 10 unloaded boards was $18USD (including shipping) from Seeed Fusion (posted to Australia).

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates