🔌 DIY Smart Energy Monitor with ESP32 & Matter Protocol: Real-Time Power Monitoring (2026 Complete Guide)
Figure 1: ESP32 Energy Monitor with OLED Display and PZEM-004T Sensor
📋 Table of Contents
- Introduction
- Components List (BOM)
- Wiring Diagram
- Arduino Code
- Matter Protocol Setup
- Home Assistant Integration
- Calibration
- FAQ
1. Introduction: Why Build a Smart Energy Monitor?
In 2026, energy costs are rising and sustainability is crucial. A DIY smart energy monitor helps you:
- Track real-time power consumption of your home appliances
- Reduce electricity bills by identifying energy-hungry devices
- Integrate with Matter protocol for universal smart home compatibility
- Save 70-80% cost compared to commercial monitors (€100-300)
- Full customization with ESP32 and open-source software
This project uses the PZEM-004T v3.0 sensor for accurate measurements and ESP32-C6 for native Matter support.
2. Components List (BOM)
Required Components:
| Component | Quantity | Price |
|---|---|---|
| ESP32-C6 DevKit (Matter native support) | 1 | €8-12 |
| PZEM-004T v3.0 (Power meter module) | 1 | €12-15 |
| OLED Display 0.96" I2C (SSD1306) | 1 | €4-6 |
| SCT-013-000 Current Transformer (100A) | 1 | €5-7 |
| AC-AC Voltage Transformer (220V to 9V) | 1 | €3-5 |
| Breadboard + Jumper Wires | 1 set | €5-8 |
| Plastic Enclosure (IP65 rated) | 1 | €6-10 |
| TOTAL | - | €43-63 |
💡 Cost Comparison: Commercial smart plugs with energy monitoring cost €30-50 per outlet. This DIY solution monitors your entire home for less!
3. Wiring Diagram
🔌 ESP32-C6 + PZEM-004T Connections:
ESP32-C6 PZEM-004T v3.0 OLED Display
───────── ────────────── ────────────
GPIO 16 (RX2) ──→ TX (PZEM)
GPIO 17 (TX2) ──→ RX (PZEM) VCC ──────────→ 3.3V
3.3V ──→ VCC GND ──────────→ GND
GND ──→ GND SCL ──────────→ GPIO 22
5V (External) ──→ VCC (PZEM Power) SDA ──────────→ GPIO 21
PZEM-004T AC Connections:
────────────────────────
L (Live) ──→ AC Live wire from mains
N (Neutral) ──→ AC Neutral wire
CT Input ──→ SCT-013 Current Transformer
⚠️ Critical: The PZEM-004T has built-in isolation, but always use proper enclosures and fuses for 220V connections.
Step-by-Step Wiring:
- PZEM-004T Setup:
- Connect AC Live (L) and Neutral (N) to PZEM terminals
- Wrap SCT-013 CT sensor around the Live wire only
- Ensure CT arrow points toward the load (correct direction)
- ESP32-C6 Connections:
- UART2: GPIO 16 (RX) ← PZEM TX
- UART2: GPIO 17 (TX) → PZEM RX
- I2C: GPIO 22 (SCL) → OLED SCL
- I2C: GPIO 21 (SDA) → OLED SDA
- Power Supply:
- ESP32-C6: 5V via USB or external 5V regulator
- PZEM-004T: 5V from ESP32 or separate 5V supply
- OLED: 3.3V from ESP32
4. Arduino Code (Matter-Ready)
/*
* Smart Energy Monitor with ESP32-C6 & Matter Protocol
* TechFix Hub - DIY Electronics & Arduino/ESP32 Projects
* Features: Real-time power monitoring, OLED display, Matter integration
*/
#include <PZEM004Tv30.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <WiFi.h>
#include <esp_matter.h>
// PZEM-004T Configuration
#define PZEM_RX 16
#define PZEM_TX 17
PZEM004Tv30 pzem(PZEM_RX, PZEM_TX);
// OLED Display Configuration
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// WiFi Configuration
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
// Measurement Variables
float voltage = 0;
float current = 0;
float power = 0;
float energy = 0;
float frequency = 0;
float pf = 0;
unsigned long lastUpdate = 0;
const unsigned long updateInterval = 2000; // Update every 2 seconds
// Matter Variables
esp_matter::endpoint_t* energy_monitor_endpoint = nullptr;
void setup() {
Serial.begin(115200);
// Initialize OLED
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Initializing...");
display.display();
delay(1000);
// Connect to WiFi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" Connected!");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
// Initialize PZEM
while (!pzem.setAddress(0x50)) {
Serial.println("PZEM communication error");
delay(1000);
}
// Initialize Matter (ESP32-C6 native support)
initMatterDevice();
display.clearDisplay();
display.println("System Ready!");
display.display();
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - lastUpdate >= updateInterval) {
lastUpdate = currentMillis;
// Read measurements from PZEM-004T
voltage = pzem.voltage();
current = pzem.current();
power = pzem.power();
energy = pzem.energy();
frequency = pzem.frequency();
pf = pzem.pf();
// Serial output
Serial.println("=== ENERGY MONITOR ===");
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); Serial.println(" kWh");
Serial.print("Frequency: "); Serial.print(frequency); Serial.println(" Hz");
Serial.print("Power Factor: "); Serial.println(pf);
Serial.println();
// Update OLED display
updateDisplay();
// Update Matter attributes
updateMatterAttributes();
// Optional: Send to MQTT or API
// sendDataToCloud();
}
}
void updateDisplay() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("U:"); display.print(voltage, 1); display.print("V ");
display.print("I:"); display.print(current, 2); display.println("A");
display.print("P:"); display.print(power, 1); display.print("W ");
display.print("PF:"); display.println(pf, 2);
display.print("E:"); display.print(energy, 3); display.println("kWh");
display.print("Freq:"); display.print(frequency, 1); display.println("Hz");
display.display();
}
void initMatterDevice() {
// Initialize Matter stack (ESP32-C6 has native Matter support)
esp_matter::init();
// Create energy monitoring endpoint
energy_monitor_endpoint = createEnergyMonitoringEndpoint();
Serial.println("Matter device initialized");
}
void updateMatterAttributes() {
if (energy_monitor_endpoint) {
// Update Matter cluster attributes
// This makes the device visible to Home Assistant, Alexa, Google Home
esp_matter::updateAttribute(energy_monitor_endpoint,
MEASUREMENT_CLUSTER_ID,
CURRENT_MEASUREMENT_ATTRIBUTE_ID,
current);
esp_matter::updateAttribute(energy_monitor_endpoint,
MEASUREMENT_CLUSTER_ID,
VOLTAGE_MEASUREMENT_ATTRIBUTE_ID,
voltage);
esp_matter::updateAttribute(energy_monitor_endpoint,
MEASUREMENT_CLUSTER_ID,
POWER_MEASUREMENT_ATTRIBUTE_ID,
power);
}
}
esp_matter::endpoint_t* createEnergyMonitoringEndpoint() {
// Create Matter endpoint for energy monitoring
// This follows Matter specification for electrical measurement
return esp_matter::endpoint::create(
esp_matter::cluster::electrical_measurement::id,
nullptr,
0
);
}
Required Libraries:
PZEM004Tv30by Jakub Mandula (Library Manager)Adafruit SSD1306by AdafruitAdafruit GFX Libraryby Adafruitesp_matter(included in ESP32-C6 Arduino core)
5. Matter Protocol Setup
Why Matter Protocol?
Matter is the new universal smart home standard (2026) that works with:
- ✅ Apple HomeKit
- ✅ Google Home
- ✅ Amazon Alexa
- ✅ Samsung SmartThings
- ✅ Home Assistant
Matter Commissioning Steps:
- Compile & Upload: Upload the code to ESP32-C6 via Arduino IDE
- Get QR Code: The ESP32-C6 will display a Matter QR code in Serial Monitor
- Scan QR Code: Use your smart home app (Home, Google Home, Alexa) to scan
- Device Appears: Your energy monitor will appear as "Electrical Measurement" device
6. Home Assistant Integration
Automatic Discovery (Matter):
If you have Home Assistant 2024.1+ with Matter integration:
- Go to Settings → Devices & Services
- Click "Add Integration" → "Matter"
- Scan the QR code from ESP32-C6 Serial Monitor
- Device auto-configures with entities:
sensor.energy_monitor_voltagesensor.energy_monitor_currentsensor.energy_monitor_powersensor.energy_monitor_energy
Manual MQTT Integration (Alternative):
# Add to configuration.yaml:
sensor:
- platform: mqtt
name: "Energy Monitor Voltage"
state_topic: "energy/monitor/voltage"
unit_of_measurement: "V"
- platform: mqtt
name: "Energy Monitor Power"
state_topic: "energy/monitor/power"
unit_of_measurement: "W"
- platform: mqtt
name: "Energy Monitor Energy"
state_topic: "energy/monitor/energy"
unit_of_measurement: "kWh"
7. Calibration
Voltage Calibration:
- Measure mains voltage with a calibrated multimeter
- Compare with PZEM reading
- Adjust calibration factor in code if needed
Current Calibration:
- Connect a known load (e.g., 100W incandescent bulb)
- Calculate theoretical current: I = P/U (e.g., 100W/230V = 0.43A)
- Compare with PZEM reading
- Adjust CT sensitivity if significant difference
8. FAQ (Frequently Asked Questions)
Can I monitor multiple circuits with one PZEM-004T?
No, one PZEM-004T monitors one circuit. For multiple circuits (e.g., different rooms), you need one PZEM-004T per circuit. You can connect multiple PZEM modules to one ESP32 using different UART ports or I2C addresses.
Is this safe for 220V/110V mains monitoring?
Yes, the PZEM-004T has built-in isolation between the high-voltage AC side and the low-voltage DC side. However, always use a proper IP65-rated enclosure, add fuses (2A for 220V), and never touch live wires. If unsure, consult a licensed electrician.
Can I access data remotely (outside my home)?
Yes! With Matter protocol, your energy monitor integrates with cloud services through your smart home hub (HomePod, Google Nest, Alexa). Alternatively, use Home Assistant Cloud (Nabu Casa) or set up port forwarding for remote access.
What's the maximum current this can measure?
With the SCT-013-000 (100A CT), you can measure up to 100A. At 230V, that's 23kW maximum power. For higher currents, use a higher-rated CT sensor (e.g., SCT-013-050 for 50A or SCT-013-200 for 200A).
Does this work with 3-phase systems?
For 3-phase monitoring, you need 3 PZEM-004T modules (one per phase). Connect each to separate UART ports on ESP32, or use an ESP32 with more UARTs. Sum the power from all three phases for total consumption.
Conclusion
Building a smart energy monitor with ESP32-C6 and Matter protocol gives you:
- ✅ Real-time power monitoring for €43-63 (vs €100-300 commercial)
- ✅ Universal compatibility (Apple, Google, Alexa, Home Assistant)
- ✅ Full customization and open-source
- ✅ Accurate measurements (±0.5% voltage, ±1% current)
- ✅ Local control (no cloud dependency)
Next Steps:
- Start with the ESP32-C6 + PZEM-004T setup
- Add OLED display for local monitoring
- Integrate with Matter for smart home control
- Explore our other IoT and Smart Home projects


