Back to Tutorial

PZEM-004T Energy Meter with ESP32 – Complete Guide (Voltage, Current, Power & Energy Monitoring)


Introduction

With the rise of IoT-based energy monitoring systems, measuring electrical parameters like voltage, current, power, and energy consumption has become essential for smart homes, industries, and research projects. The PZEM-004T v3.0 energy meter module combined with the ESP32 microcontroller is a powerful, low-cost solution for real-time AC power monitoring.

In this blog, we will learn how to interface PZEM-004T with ESP32, understand its working principle, wiring, and Arduino code, and explore real-world applications.


What is PZEM-004T?

The PZEM-004T is a single-phase AC energy monitoring module capable of measuring:

  • AC Voltage (80–260V)
  • AC Current (up to 100A with CT)
  • Active Power (Watt)
  • Energy Consumption (kWh)
  • Frequency (Hz)
  • Power Factor

It communicates with microcontrollers using TTL serial communication (UART).


Why Use ESP32 with PZEM-004T?

The ESP32 is an excellent choice for energy monitoring because:

  • Built-in Wi-Fi & Bluetooth
  • Multiple hardware UARTs
  • High processing speed
  • Ideal for IoT dashboards (Blynk, MQTT, Firebase, ThingsBoard)

This combination allows you to monitor energy data locally and remotely.


PZEM-004T v3.0 Key Features

  • Measurement Range:
    • Voltage: 80–260V AC
    • Current: 0–100A
  • Communication: UART (9600 baud)
  • Built-in energy storage (non-volatile)
  • External current transformer (CT)
  • Compact & reliable

Required Components

  • ESP32 Dev Board
  • PZEM-004T v3.0 Module
  • Current Transformer (CT)
  • Connecting Wires
  • AC Load (for testing)

⚠️ Warning: This module works with high voltage AC. Take proper safety precautions.


PZEM-004T to ESP32 Connection Diagram


PZEM-004T PinESP32 Pin
TXGPIO 16 (RX2)
RXGPIO 17 (TX2)
VCC5V
GNDGND

ESP32 supports multiple UARTs, so we use Serial2 for stable communication.


PZEM-004T ESP32 Arduino Code

Install the PZEM004Tv30 library from GitHub or Arduino Library Manager before uploading the code.



// https://github.com/mandulaj/PZEM-004T-v30
#include <PZEM004Tv30.h>
#include <HardwareSerial.h>

// PZEM pins
#define RX_PIN 16   // ESP32 RX ← PZEM TX
#define TX_PIN 17   // ESP32 TX → PZEM RX

// Use UART2
HardwareSerial pzemSerial(2);

// Create PZEM object
PZEM004Tv30 pzem(pzemSerial, RX_PIN, TX_PIN);

void setup() {
  Serial.begin(115200);

  // Start UART2
  pzemSerial.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN);

  Serial.println("PZEM-004T V3.0 Power Meter Reading");
}

void loop() {
  Serial.print("Custom Address: 0x");
  Serial.println(pzem.readAddress(), HEX);

  float voltage   = pzem.voltage();
  float current   = pzem.current();
  float power     = pzem.power();
  float energy    = pzem.energy();
  float frequency = pzem.frequency();
  float pf        = pzem.pf();

  if (isnan(voltage) || isnan(current)) {
    Serial.println("⚠️ PZEM not responding!");
  } else {
    Serial.print("Voltage: ");   Serial.print(voltage);   Serial.println(" V");
    Serial.print("Current: ");   Serial.print(current);   Serial.println(" A");
    Serial.print("Power: ");     Serial.print(power);     Serial.println(" W");
    Serial.print("Energy: ");    Serial.print(energy, 3); Serial.println(" kWh");
    Serial.print("Frequency: "); Serial.print(frequency); Serial.println(" Hz");
    Serial.print("PF: ");        Serial.println(pf);
  }

  Serial.println("----------------------");
  delay(2000);
}

👇How It Works

  1. PZEM-004T measures AC parameters using internal sensing circuits.
  2. Data is sent via UART to ESP32.
  3. ESP32 processes and displays data on Serial Monitor.
  4. Data can be uploaded to cloud dashboards via Wi-Fi.

Applications of PZEM-004T with ESP32

  • Smart Energy Meter
  • Home Automation Power Monitoring
  • Industrial Load Analysis
  • Solar Energy Monitoring
  • Electricity Theft Detection
  • IoT-based Billing System

Advantages of Using PZEM-004T

  • Accurate and stable readings
  • Easy to interface
  • Non-volatile energy memory
  • Cost-effective solution
  • Ideal for IoT projects

Common Issues & Solutions

Issue: No data on Serial Monitor
✔ Check RX/TX connections
✔ Ensure baud rate is 9600

Issue: NaN values
✔ Load must be connected
✔ Ensure CT direction is correct


Conclusion

The PZEM-004T with ESP32 is a powerful combination for building smart energy monitoring systems. With minimal components and simple code, you can measure real-time electrical parameters and integrate them into IoT platforms.

This project is perfect for students, startups, and innovators working on smart grid and energy optimization solutions.

Share this post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Tutorial