Maker.io main logo

High Precision Digital AC Energy Meter Circuit

2022-08-03 | By Hesam Moshiri

License: Attribution-NonCommercial-ShareAlike Current Voltage

Disclaimer: Some parts of this circuit carry dangerous Mains voltage. Be careful with your experiments. If you are a beginner, ask some experienced users to guide you. 

Dealing with the 220V-AC mains voltage and measuring the AC loads' true power, voltage, and current parameters are always considered a big challenge for electronic designers, both in circuit design and calculations. The situation gets more complex when we deal with the inductive loads because inductive loads alter the sine-wave shape of the AC signal (resistive loads don’t).

In this article/video, I introduced a circuit that can measure the AC voltage, RMS current, active power, apparent power, power factor, and energy consumption (KWh) of the loads. I used an Arduino-Nano board as a processor to make this more educational-friendly and attractive even for beginners. The device independently measures the aforementioned parameters and displays the results on a 4*20 LCD. The measurement error rate is around 0.5% or lower.

To design the schematic and PCB, I used Altium designer 22 and installed the missing component libraries using Altium’s manufacturer part search. I used the Siglent SDM3045X benchtop multimeter to calibrate the board.

It's a cool device to be used in everyday electronics, so let’s get started :-)

YouTube: https://www.youtube.com/watch?v=1I6Bz7_DOGs

 

A. Circuit Analysis

Figure 1 shows the schematic diagram of the AC energy measurement circuit. As it is clear, two main components of the design are the Arduino-Nano board [1] and the HLW8032 [2] chip.

 Digital AC Energy Meter Circuit 1

Figure 1

schematic diagram of the digital AC energy meter device

 

A-1. Mains Input

I start to explain the schematic from top to bottom. P1 and P2 are power connectors to provide strong screw-connection for the 220V mains and the load. C1 is a 100nF X2 rated capacitor that reduces the input noise. F1, R1, and R2 provide mains input protection. T1 is a common mode choke that was also used to reduce the common-mode noise.

R3, R4, R5, and R6 are 4-milliohm 2512 resistors in parallel to build a 4W 1-milliohm shunt resistor. You should select these resistors from 1% 2512 package resistors. If for whatever reason you had no access to these resistors, you can use two 2-milliohm resistors in parallel, however, the aforementioned combination provides the best result in terms of accuracy and the rated shunt power.

A-2. Non-Isolated Supply

The power supply of the HLW8032 chip should be non-isolated, mains referenced. The reason is that the chip must read the shunt resistor and mains voltage values directly. C2 is a 470nF-630V capacitor that reduces the mains voltage and R8 was used to limit the current. R7 reduces the discharge time of C2. D1 and D2 are rectifier diodes and D3 is a 15V zener diode to regulate the voltage at around 15V. C4, C5, and R9 create a low-pass RC filter to reduce the noise as much as possible.

REG-1 is the TS2937CW50 [3] 5V linear regulator. As it is clear, it regulates and fixes the voltage to 5V. C3 is the output capacitor and it reduces the regulator noise.

A-3. Isolated Supply

This section consists of U1, which is the HLK-PM01 AC to DC conversion module. It provides an isolated supply for the Arduino board. C6, C7, and L1 provide a low-pass Pi filter to reduce the output noise of U1.

A-4. Energy Meter 

The main component of this section is IC1 which is the HLW8032 chip. According to the datasheet: “HLW8032 is a high-precision electric energy metering IC that is manufactured using CMOS process and is mainly applied to single-phase applications. It can measure line voltage and current and calculate active power, apparent power, and power factor. The interior of the device integrates two ∑-Δ ADCs and one high-precision inner core of electric energy metering. Able to communicate data via UART port, HLW8032 adopts a 5V power supply and built-in 3.579M crystal oscillator and uses SOP packaging with 8Pin. Featured with high precision, low power consumption, high reliability, strong adaptability to the environment, etc., HLW8032 applies to electric energy metering for power consumers with a single-phase two-wire system.”

C8 and C9 are decoupling capacitors. C10, C11, R12, and R15 are part of the shunt resistor reading network (see the datasheet). R16...R20, and C12 are also part of the voltage measurement network (see the datasheet). IC2 and IC3 are digital isolators (optocouplers) to transfer digital serial signals to the Arduino board. R10 and R13 are pull-up resistors.

A-5. Arduino Nano

AR1 is the famous Arduino-nano board and IDC1 is the 2*8 IDC connector to connect a 4*20 Green-Backlight Character-LCD to the board. R23…R26 are pulldown resistors and R22 adjusts the contrast of the LCD. C13 and C14 are decoupling capacitors.

B. PCB Layout

Figure 2 shows the PCB layout of the design. It is a two layers PCB board and I used a variety of SMD and through-hole components. Figure 3 shows a 3D view of the PCB board and assembly drawings.

 Digital AC Energy Meter Circuit 2

Figure 2

PCB layout of the digital energy meter circuit

 Digital AC Energy Meter Circuit 3

Figure 3

A 3D view of the PCB board and assembly drawings

 

C. Calibration

To calibrate the device, you only need a resistive load (such as an incandescent light bulb, not an LED one!) and an accurate RMS multimeter. I used the Siglent SDM3045X multimeter (figure 4). Please watch the YouTube video for more details.

 Digital AC Energy Meter Circuit

Figure 4

RMS current measurement (calibration process)

 

After you followed the procedure, you must change the shunt resistor value in the “HLW8032.h” header file (Arduino library). Go to line 62 and modify the “float CurrentRF” value. In my case, the best value was 0.0012. 

D. Code

The Arduino code has been inserted below. You can also download the Arduino library from my own GitHub storage [4]. I assume you know how to manually install an Arduino library. It’s pretty easy.

Copy Code
#include "HLW8032.h"
#include <LiquidCrystal.h>
#define SYNC_TIME 500


const int rs = 12, en = 11, d4 = 10, d5 = 9, d6 = 8, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


static unsigned long start_time, end_time;
HLW8032 HL;


void setup()
{
lcd.begin(20, 4);
HL.begin(Serial, 4);
start_time = millis();
}

void loop()
{


end_time = millis();
HL.SerialReadLoop();


if (end_time - start_time > SYNC_TIME)
{
if (HL.SerialRead == 1)
{
lcd.setCursor(0, 0);
lcd.print("Voltage[V]: ");
lcd.setCursor(12, 0);
lcd.print(HL.GetVol() * 0.001, 2);


lcd.setCursor(0, 1);
lcd.print("Current[A]: ");
lcd.setCursor(12, 1);
lcd.print(HL.GetCurrent(), 2);


lcd.setCursor(0, 2);
lcd.print("Power[W]: ");
lcd.setCursor(10, 2);
lcd.print(HL.GetActivePower() * 0.001, 2);


lcd.setCursor(0, 3);
lcd.print("Energy[KWh]: ");
lcd.setCursor(13, 3);
lcd.print(HL.GetKWh(), 2);
}
start_time = end_time;
}
}

 E. Testing

After calibration, you can use the device anywhere you like. Figure 5 shows the printed information on the LCD screen. There are many use cases for this device at your workplace and home. Have fun!

 Digital AC Energy Meter Circuit  5

Figure 5

Calculated parameters of the AC load (voltage, current, power, KWh)

F. LCD Display

The LCD is a standard Green-Backlight 4*20 Character-LCD. The connection type between the LCD and board is the direct point-to-point connection. It means the first Pin of the IDC (left side) is connected to the first Pin of the LCD from the left side (VSS). Figure 6 shows the LCD wiring.

 Digital AC Energy Meter Circuit  6

Figure 6

4*20 LCD connection to the board

 

G. Bill of materials

Figure 7 shows the bill of materials.

 Digital AC Energy Meter Circuit  7

Figure 7

Bill of materials

 

H. References

[1]: Arduino-Nano: https://www.digikey.com/en/products/detail/arduino/A000005/2638989

[2]: HLW8032 English datasheet: https://github.com/MyVanitar/HLW8032/blob/main/DS_HLW8032_EN_Rev1.5.pdf

[3]: TS2937CW50 (LM2937): https://www.digikey.com/en/products/detail/taiwan-semiconductor-corporation/TS2937CW50-RPG/7370087

[4]: HLW8032 Arduino Library: https://github.com/MyVanitar/HLW8032

制造商零件编号 A000005
ARDUINO NANO ATMEGA328 EVAL BRD
Arduino
¥172.33
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum