- Note: Power supply of HLW8012 and AC Mian Live and natural should be NOT isolated.
- Note: Better use optical-coupler to send signal to your MCU, this make it isolated. MCU shared power supply with HLW8012 is not a good idea.
Power supply of HLW8012
- More non-isoated power module refer to AC-DC
In order to match the resistance sampling method (ie, direct sampling signal from the grid, non-isolated), the power supply circuit must be non-isolated power supply, non-isolated power supply in two ways: AC-DC non-isolated power supply, The comparison is as follows:
- LNK304 designed AC-DC non-isolated power supply
The use of LNK304 designed AC-DC non-isolated power supply, L and N, respectively, is the AC line and the zero line to zero line as a ground. This circuit does not need transformer, regulator 5V, can provide about 150mA current, to ensure that AC85V ~ 265V AC range, to achieve a stable voltage output, ripple is also very small, about 50mV. This power supply provides operating voltage for all modules.
- Resistive buck power supply
After the regulator capacitor C1 step-down, the diode rectifier, the use of 1N4749 power down to 24V, and then through the regulator chip 78L05 output power stabilized at 5V, to provide power to the HLW8012, 24V for driving the relay. If the choice of 12V relay, then 1N4749 need to be changed to 1N4742, but the safety capacitor C1 need to be changed to 1uF capacitor to improve the drive current.
HLW8012 Pin Definition
- High-frequency pulse CF, indicating active power, in the range of 1000: 1 to achieve ± 0.3% accuracy
- High frequency pulse CF1, indicating current or voltage rms, using SEL selection, ± 0.5% accuracy in the 500: 1 range
- Built-in crystal, 2.43V voltage reference source and power monitoring circuit
- 5V single power supply, operating current less than 3mA
- Fcf = Power, Fcf1 = current, Fcfu = voltage
- V1: Voltage signal on the current channel pin
- V2: Voltage signal on voltage channel pin
- Fosc: built-in crystal, the typical frequency of about 3.579MHz;
- Vref: built-in reference source, the typical voltage is 2.43V
Use with ESP8266
- Download demo code from our github
- The demo code will monitoring the power, current, voltage and frequency, you can monitor it via telnet to see remote debug output, same as serial output, but safe when AC main power connected.
- Pin definition to esp8266 please see the comments in sketch
- Also can calibrate the parameters, see the comments in sketch
- Enter SSID and password in the sketch, run the demo code first to see IP address
- Connect to AC main power, login remotely via telnet, in windows for example, command: telnet 192.168.0.100
- Demo -1: on board sample resistor is 0.002R, 2mR, diameter 2.5mm, rate current is 20A. space is 10mm, height 7.5mm, "door" shape.
- Demo -2 PCB File
- Make sure use baud rate 4800 to read data
- Demo Video HLW8012 http://v.youku.com/v_show/id_XMjY3ODQ5ODMxMg==.html
- Demo code here, initiate version - https://github.com/Edragon/Arduino/tree/master/Sketchbook/04_sensor
Tips to use with ESP8266:
- Use Wemos and its softserial, wiring should be
- HLW8032 RX to Wemos D5
- HLW8032 3.3V to Wemos 5V or 3.3V
- HLW8032 GND pin to Wemos GND
- Upload sketch this one to wemos, Open serial monitor to check data, notice raw data in HEX ouptut
- Bypass on board AC-DC converter to analyze data directly, see post here.
Method 2 (obsolete)
- The wiring should be:
HLW8032 RX -> ESP8266 RX pin HLW8032 3.3V -> ESP8266 3.3V, also works on 5V HLW8032 GND -> ESP8266 GND
- Better not use with wemos board, which has USB-TTL UART bridge circuits on board, could cause conflict to uart reading from hlw8032. Please use a standalone ESP8266 module or board, without this circuits, for example our esp-12f adapter board
- Better not use with ESP-link firmware, data can be read, but not in the raw hex data. Better write your own code to read and analyze the data by esp8266
- Again double check baudrate should be 4800, in case for ESP-LINK, options should set to "8E1", data could be read but incomplete
- The test could see here: https://twitter.com/electro_phoenix/status/1104004115422539781
- Not yet have demo code of this available now.
Use Isolated ZMPT Sensor Version
- Find the design documents (chinese) here
- Use a already-known load to calculate the coefficience first
- The math for Voltage is, same for current and power, voltage value is in register bit 2~4, voltage_value is 5~7
Voltage = (voltage_register / voltage_value) * voltage_coefficent.
- For example for voltage 220V, you can calculate the value of voltage_coefficent
22V = (voltage_register / voltage_value) * voltage_coefficent.
* Use voltage_coefficent as a constant value for further reading.
- Notice voltage_register is different for every chip.
- Data read when only power by 5V, not load, not yet connect to AC mains
55 5A 02 DA 78 07 26 72 00 3D 3B 07 27 5B 4C C4 58 D0 A7 87 61 00 01 BC F2 5A 02 DA 78 07 28 BB 00 3D 3B 04 35 B5 4C C4 58 11 9F 4F 61 00 00 6C => F2 / 5A / 02 DA 78 / 07 28 BB / 00 3D 3B / 04 35 B5 / 4C C4 58 / 11 9F 4F / 61 / 00 00 / 6C => state: F2 / check: 5A / Voltage parameter REG: 02 DA 78 / Voltage REG: 07 28 BB / Current Parameter REG: 00 3D 3B / Current REG: 04 35 B5 / Power parameter REG: 4C C4 58 / Power REG: 11 9F 4F / Data Updata REG: 61 / PF REG: 00 00 / CheckSum REG: 6C
- HLW Datasheet please find here.
- All demo codes please find here.
- Arduino demo code please see our arduino github.
Other reference, energy monitor ICs: