Digital AC Energy Measurement Circuit: Voltage, Current, Power, PF, KWh
2023-10-09 | By Hesam Moshiri
License: Attribution Non-Commercial No Derivatives
Disclaimer: Some parts of this circuit carry dangerous Mains voltage. If you are a beginner, seek guidance from experienced users.
Dealing with the 110V/220V AC mains voltage and measuring the AC load parameters are regarded as a challenge for electronic designers, both in circuit design and calculations. The situation becomes more complex when dealing with inductive loads because they cause a phase shift between voltage and current and alter the sine-wave shape of the AC signal (resistive loads do not). The power factor of resistive loads is theoretically equal to 1.
In this article/video, I introduce a circuit that can measure AC RMS voltage, RMS current, active power, power factor, and energy consumption (KWh) of the loads. I used a low-cost STM32 Microcontroller and provided four push buttons for initial calibration. The device can independently measure the parameters and display the results on a bright 1.3-inch OLED display. The measurement error rate is around 0.5% or lower.
For the schematic and PCB design, I use Altium Designer 23. I shared the PCB project with my colleague for feedback and edits through Altium 365's secure cloud space. I used the Siglent SDM3045X benchtop multimeter to calibrate the circuit. That’s a quick and easy process.
It's a cool device for everyday electronics, so let’s get started! :-)
Circuit Analysis
Figure 1 shows the schematic diagram of the AC-Mains input and shunt resistor. P1 and P2 are input/output terminals for the AC input and load connection.
Figure 1, Schematic diagram of the AC input, Load terminal, shunt resistor, and input protection
F1 is a 500mA fuse [1] and R1 is the 7D471 varistor [2] to protect the device against high-voltage transients. T1 is a 10mH common mode choke [3] and C1 is a 100nF-X2 capacitor [4] to reduce the noise. The circuit shunt resistor should be a 1-milliohm resistor; however, the power rating of the shunt also matters. Therefore, 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, isolated output and non-isolated. The power supply of the measurement part should be non-isolated and referenced to one of the AC-Mains terminals.
Figure 2, The power supply section of the circuit
C2 is a 470nF-630V capacitor [5] to reduce the AC voltage. R6 discharges the capacitor at power OFF. D1 and D3 are 1N4007 [6] diodes to rectify the AC voltage and D2 reduces to voltage to be applied to the 78L05 [7] regulator. U1 is the HLK-PM01 [8] AC to DC conversion module that converts 220V-AC to 5V-DC. C5, L1, and C6 create a Pi network to reduce the noise REG2 is the SPX3819M5 regulator [9] to prepare a 3.3V supply rail. C7 stabilizes the output of the regulator.
Figure 3 shows the measurement part that consists of the HLW8032 chip, PC817 optocoupler [10], and some passive components.
Figure 3, The measurement section of the circuit
C8 and C9 are decoupling capacitors to reduce the noise of the IC1 supply. R10 limits the current of the optocoupler diode and R11 is a pull-up resistor for the collector of the transistor. R13 … R17 resistors reduce the input voltage to be applied to the IC1 and C12 reduces the high-frequency noise.
Figure 4 shows the microcontroller section of the board which mainly consists of the STM32G030F6 microcontroller [11]. R18 … R21 are pull-up resistors and C13 … C16 are debouncing capacitors for SW1 … SW4. OCS is the 16MHz oscillator XO [12] to prepare 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, The microcontroller section of the circuit
PCB Layout
Figure 5 shows the PCB layout of the design. It’s a two-layer PCB board with a mixture of SMD and through-hole components. Figure 6 shows the wiring diagram of the board. Figure 7 shows the assembled board.
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
Calibration & Code
To calibrate the board, you need to have an accurate True RMS multimeter. Please watch the YouTube video completely for more information. You can download the compiled HEX file from here [14].
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.
Visit TechForum