This guide details the construction of a cost-effective and user-friendly IoT-based AC energy meter using readily available components. The project leverages the capabilities of an ESP32 microcontroller and a PZEM-004T AC energy meter module to create a real-time energy monitoring system accessible via a web interface. This eliminates the need for expensive pre-built solutions, offering a practical and insightful approach to energy consumption tracking. The guide provides a step-by-step process, including component selection, circuit diagrams, and code examples, suitable for both experienced and novice electronics enthusiasts.By combining the ESP32's WiFi capabilities with the PZEM-004T's Modbus RTU communication protocol, this project demonstrates a powerful yet simple solution for monitoring crucial energy parameters. The use of asynchronous web server technology ensures a smooth and responsive user experience, constantly updating a dashboard with voltage, current, power, energy consumption, frequency, and power factor readings. This accessible, real-time data empowers users to effectively manage and understand their energy usage.
Pros And Cons
- Compact single-phase AC power monitoring module
- Measures voltage (80-260V), current (up to 100A via external CT), active power, energy consumption, frequency, and power factor
- Communicates via Modbus RTU protocol over TTL serial
- Easy to interface with microcontrollers (Arduino, ESP32)
- Built-in galvanic isolation and non-invasive current transformer prioritize safety
- Version 1.0 has design and reading issues; Version 3.0 recommended
Read more: AMI Meter Reading Guide: Understanding Your Smart Electricity Meter
Components and PZEM-004T Module Details
To build this IoT-based AC energy meter, you'll need an ESP32 microcontroller, a PZEM-004T AC energy meter module, a current transformer (either open or closed core), several electrical wires, and an electrical load for testing (e.g., a light bulb).

The PZEM-004T is a single-phase AC power monitoring module measuring voltage (80-260V), current (up to 100A via an external CT), active power, energy consumption, frequency, and power factor. It communicates using Modbus RTU over TTL serial, making it easy to interface with microcontrollers.

It's crucial to use the latest version 3.0 of the PZEM-004T for accuracy. The older version 1.0 had some known issues. Both open and closed core 100A current transformers are compatible.
Testing with Arduino
Before interfacing with the ESP32, I initially tested the PZEM-004T with an Arduino Nano. I used example code from a library, connecting the module, load, and power wires as shown in the circuit diagram.

The Arduino code successfully displayed voltage, current, power, energy, frequency, and power factor on the serial monitor. These values were then displayed on a 16x2 LCD screen after modifying the Arduino code.

This step validated the PZEM-004T's functionality and provided a baseline for the ESP32 integration.
ESP32 Implementation and Web Server Setup
The core of the project involves using the ESP32 to create an asynchronous web server to display energy readings in real time. I used the ESP32's WiFi capabilities, the ESP Async Web Server library, and the Async TCP library for this purpose.

The code includes WiFi credentials, hardware serial pin definitions for communication with the PZEM-004T, and custom HTML and CSS for a user-friendly web interface. JavaScript handles the HTTP requests for data retrieval and updates the web page dynamically.

The ESP32 code reads data from the PZEM-004T, processes it, and updates the webpage without the need for constant refreshes, creating a dynamic, real-time dashboard
Results and Conclusion
The final IoT AC energy meter successfully displays voltage, current, power, energy, frequency, and power factor in real-time on a web dashboard accessible from various devices (PC, tablet, smartphone).

The asynchronous web server design eliminates the need for manual page refreshes, ensuring a constantly updated display. The system is accurate and easy to set up, making it a practical solution for monitoring AC energy consumption.

The use of the PZEM-004T v3.0, ESP32, and appropriate libraries results in a robust and reliable energy monitoring system. It is highly recommended for anyone looking to build a user-friendly real-time energy monitoring solution.