HLW8012 Energy Metering IC — Pinout, Working, and Applications
Introduction
The HLW8012 is a highly integrated single-phase energy metering IC designed for real-time measurement of AC voltage, current, power, and energy consumption.
Manufactured by Hi-Link, this IC is popular in IoT-based smart plugs, smart meters, and home automation systems due to its compact design, digital output interface, and cost efficiency.
Unlike traditional analog metering chips, the HLW8012 directly provides pulse outputs proportional to active power and RMS current, simplifying interface with microcontrollers like ESP8266, ESP32, or Arduino.
⚙️ Key Features
- Measures AC Voltage, Current, and Active Power
- Provides frequency (pulse) output proportional to:
- Active Power → CF pin
- RMS Current or Voltage → CF1 pin
- Built-in multiplexed ADCs for voltage and current sensing
- Selectable channel output (voltage or current) via SEL pin
- Simple calibration using a reference load
- 5V supply operation (can work from 3.3V with level shifting)
- Low external component count
- Excellent for IoT and smart energy monitoring
️ Pin Configuration of HLW8012
| Pin No. | Name | Type | Description |
| 1 | V2P | Input | Voltage sensing input (connected via resistor divider from AC line) |
| 2 | V2N | Input | Negative reference for voltage channel |
| 3 | IP | Input | Current sense input from current shunt resistor |
| 4 | IN | Input | Negative reference for current channel |
| 5 | SEL | Input | Selects CF1 output mode:• High = Current output• Low = Voltage output |
| 6 | CF1 | Output | Frequency output proportional to current or voltage (based on SEL pin) |
| 7 | CF | Output | Frequency output proportional to active power |
| 8 | REVP | Output | Reverse polarity indicator (High if reverse power detected) |
| 9 | VDD | Power | Positive supply voltage (typically 5V) |
| 10 | GND | Power | Ground reference |
Working Principle
The HLW8012 works by sampling voltage and current waveforms via internal ADCs.
- Voltage Measurement
- The AC mains voltage is divided down using a high-value resistor network and applied to the V2P/V2N inputs.
- Current Measurement
- The load current passes through a low-value shunt resistor.
- The resulting voltage drop is sensed across IP/IN pins.
- Signal Processing
- The chip multiplies the instantaneous voltage and current values to calculate active power.
- The RMS values of voltage and current are also computed internally.
- Output Representation
- The chip outputs digital pulses:
- CF → proportional to active power
- CF1 → proportional to RMS voltage or current (selectable by SEL pin)
- By counting pulses over time, a microcontroller can easily determine energy (Wh) and power (W).
- The chip outputs digital pulses:
Interfacing HLW8012 with Microcontroller
Typically, HLW8012 is connected to an ESP8266 or ESP32 as follows:
- CF → GPIO input (to measure active power)
- CF1 → GPIO input (to measure current or voltage)
- SEL → GPIO output (to toggle between current and voltage measurement)
- Shunt resistor on IP–IN side for current sensing
- Voltage divider on V2P–V2N side for voltage sensing
A microcontroller measures the pulse frequency, computes the ratio with calibration constants, and displays the power, current, voltage, and energy on a web dashboard or LCD.
Typical Calibration Formula
After interfacing, you can derive readings as:
where
- ( f_CF ) = Pulse frequency from CF pin
- ( f_CF1 ) = Pulse frequency from CF1 pin
- ( K_p, K_i ) = Calibration constants (determined experimentally)
Applications
- Smart Energy Monitors
- IoT Smart Plugs
- Home Automation Power Modules
- Appliance Energy Logging
- Smart Meters
- Overload Protection Circuits
⚡ Advantages
- Low-cost and accurate single-phase energy measurement
- Easy to interface with 3.3V MCUs
- Requires minimal external circuitry
- Direct frequency output simplifies digital measurement
- Supports reverse polarity detection
⚠️ Precautions
- Ensure proper isolation when dealing with mains voltage.
- Always use opto-isolators or voltage dividers rated for AC line sensing.
- Calibrate using a known resistive load for accuracy.

No comments