By Hesam Moshiri, Anson Bao

Copyright: Attribution-NonCommercial-NoDerivs (CC-BY-NC-ND)

Disclaimer: Some parts of this circuit carry dangerous mains voltage. If you are a beginner, please seek guidance from experienced users.

Working with 110V/220V AC mains voltage and measuring the AC load parameters presents a significant challenge for electronic designers, both in terms of circuit design and calculations. The complexity increases when dealing with inductive loads, as they cause a phase shift between voltage and current, and distort the sine-wave shape of the AC signal (which does not happen with resistive loads). The power factor for resistive loads is theoretically equal to 1.

In this article/video, I present a circuit designed to measure AC RMS voltage, RMS current, active power, power factor, and energy consumption (KWh) of loads. I used a low-cost STM32 Microcontroller and incorporated four push buttons for initial calibration. The device independently measures the parameters and displays the results on a bright 1.3-inch OLED display. The measurement accuracy is around 0.5% or better.

For the schematic and PCB design, I used Altium Designer 23. I shared the PCB project with a colleague for feedback and edits via Altium 365’s secure cloud space. The Octopart component search engine proved invaluable for sourcing component information and generating the Bill-of-Materials (BOM). To ensure high-quality PCB production, I sent the Gerber files to Wellcircuits. I used the Siglent SDM3045X benchtop multimeter for calibration, which is a quick and simple process.

This is a fantastic device for everyday electronics, so let’s dive in! 🙂

Download the Gerber files or order 10 high-quality PCB boards for just $5

If you would like to order a fully assembled PCB (including free shipping), click here

Circuit Analysis

Figure 1 shows the schematic diagram of the AC mains input and the shunt resistor. P1 and P2 are the input/output terminals for the AC input and load connections.

Figure 1

Schematic diagram of the AC input, load terminal, shunt resistor, and input protection

F1 is a 500mA fuse [1], and R1 is a 7D471 varistor [2] to protect the device from high-voltage transients. T1 is a 10mH common-mode choke [3], and C1 is a 100nF-X2 capacitor [4] to reduce noise. The shunt resistor should be a 1-milliohm resistor, but its power rating is also important. You can use R2 … R5 resistors in parallel to increase the power rating of the shunt to up to 12W, by using four 4-milliohm, 3W resistors in parallel. In my case, I used two 2-milliohm resistors in parallel.

Figure 2 shows the power supply section of the circuit, including both isolated and non-isolated outputs. The power supply for the measurement section should be non-isolated and referenced to one of the AC mains terminals.

Figure 2

Power supply section of the circuit

C2 is a 470nF-630V capacitor [5] to reduce the AC voltage. R6 discharges the capacitor when the power is off. D1 and D3 are 1N4007 diodes [6] used for rectifying the AC voltage, and D2 reduces the voltage before applying it to the 78L05 regulator [7]. U1 is the HLK-PM01 [8] AC-to-DC conversion module, which converts 220V AC to 5V DC. C5, L1, and C6 form a Pi network to reduce noise. REG2 is the SPX3819M5 regulator [9], which generates the 3.3V supply rail, and C7 stabilizes the regulator’s output.

Figure 3 shows the measurement section of the circuit, consisting of the HLW8032 chip, PC817 optocoupler [10], and various passive components.

Figure 3

Measurement section of the circuit

C8 and C9 are decoupling capacitors to reduce noise on the IC1 supply. R10 limits the current through the optocoupler diode, and R11 is a pull-up resistor for the transistor’s collector. Resistors R13 … R17 reduce the input voltage applied to IC1, and C12 filters high-frequency noise.

Figure 4 shows the microcontroller section of the board, primarily consisting of the STM32G030F6 microcontroller [11]. R18 … R21 are pull-up resistors, and C13 … C16 are debouncing capacitors for switches SW1 … SW4. OCS is the 16MHz oscillator XO [12] that provides the clock for the MCU. T2, T3 [13], R22, and R23 are used for level conversion between the MCU and the OLED display module.

Figure 4

Microcontroller section of the circuit

PCB Layout

Figure 5 shows the PCB layout of the design. It’s a two-layer PCB with a mix of SMD and through-hole components. Figure 6 shows the board’s wiring diagram, and Figure 7 shows the assembled PCB. If you are a beginner or don’t have time to purchase and solder the components yourself, you can order the board fully assembled.

Figure 5

PCB layout of the AC energy meter circuit

Figure 6

Wiring diagram of the AC energy meter circuit

Figure 7

Assembled PCB board of the AC energy meter circuit

Leave a Comment

Contact

WellCircuits
More than PCB

Upload your GerberFile(7z,rar,zip)