A dual-channel AC energy monitoring node built on the ESP32-S3, measuring both Home Load and Grid (WAPDA) power simultaneously using two PZEM-004T v3.0 sensors.
Data is pushed live to Firebase Realtime Database, shown on a local SSD1306 OLED, and served via a built-in web dashboard over the ESP32's soft-AP.
This module is part of the larger βοΈ SolarPlanner Project.
Live demo of the hardware in action β OLED boot animation, real-time readings on both channels, and the web dashboard updating every 2 seconds.
demo.mp4
The monitor runs in WiFi dual mode (AP + STA):
| Mode | Purpose |
|---|---|
Soft-AP (Solar_Planner_AP) |
Always-on hotspot β devices connect directly to see the web dashboard at 192.168.4.1 |
| Station (STA) | Connects to your router β pushes data to Firebase RTDB every 5 seconds |
| Component | Qty | Purpose |
|---|---|---|
| ESP32-S3 DevKit | 1 | Main microcontroller |
| PZEM-004T v3.0 | 2 | AC power measurement (Home + Grid) |
| SSD1306 OLED (128Γ64, IΒ²C) | 1 | Real-time local display |
| Current Transformer (CT) | 2 | Non-invasive current sensing |
| 5V Power Supply | 1 | Powers the ESP32 + OLED |
| Status LED | 1 | WiFi connection indicator |
| Jumper wires, enclosure | β | Assembly |
| OLED Pin | ESP32-S3 GPIO | Notes |
|---|---|---|
| VCC | 3.3V | Do NOT use 5V |
| GND | GND | β |
| SDA | GPIO 8 | IΒ²C Data |
| SCL | GPIO 9 | IΒ²C Clock |
| PZEM Pin | ESP32-S3 GPIO | Notes |
|---|---|---|
| VCC | 5V | Powered separately |
| GND | GND | Common ground |
| RX | GPIO 15 | ESP TX β PZEM RX |
| TX | GPIO 16 | PZEM TX β ESP RX |
UART2 (
HardwareSerial(2)) βpzem1Serial
| PZEM Pin | ESP32-S3 GPIO | Notes |
|---|---|---|
| VCC | 5V | Powered separately |
| GND | GND | Common ground |
| RX | GPIO 17 | ESP TX β PZEM RX |
| TX | GPIO 18 | PZEM TX β ESP RX |
UART1 (
HardwareSerial(1)) βpzem2Serial
| Component | GPIO | Notes |
|---|---|---|
| LED (+ resistor) | GPIO 2 | Solid = WiFi connected, Blink = connecting |
β οΈ Safety: The PZEM-004T connects directly to mains AC voltage (live/neutral terminals). Always work with the power off. Use proper insulated wiring and a secure enclosure.
The editable source (DrawIO) is included: Circuit Diagram.drawio
Install all of these via Arduino IDE β Library Manager (or lib_deps in PlatformIO):
| Library | Version | Install |
|---|---|---|
| Adafruit SSD1306 | β₯ 2.5 | Library Manager |
| Adafruit GFX Library | β₯ 1.11 | Library Manager |
| PZEM-004T v3.0 | β₯ 1.1 | Library Manager |
| Firebase ESP Client | β₯ 4.x | Library Manager |
Board Package: esp32 by Espressif (β₯ 2.0) β add via Boards Manager with URL:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
git clone https://github.com/YOUR_USERNAME/SolarPlanner-DualEnergyMonitor.git
cd SolarPlanner-DualEnergyMonitor# Copy the example template
cp secrets.h.example doublepzemwithdisplayfirebase/secrets.hThen open doublepzemwithdisplayfirebase/secrets.h and fill in your credentials:
#define AP_SSID "Solar_Planner_AP" // Name of your ESP32 hotspot
#define ROUTER_SSID "YourWiFiName" // Your router SSID
#define ROUTER_PASSWORD "YourWiFiPassword" // Your router password
#define API_KEY "AIzaSy..." // Firebase API key
#define DATABASE_URL "https://your-project-default-rtdb.firebaseio.com/"- Go to Firebase Console β Create Project
- Enable Realtime Database (start in test mode)
- Go to Project Settings β General β copy the Web API Key
- Copy the Database URL from the RTDB dashboard
- Paste both into your
secrets.h
- Open
doublepzemwithdisplayfirebase/doublepzemwithdisplayfirebase.ino - Select board: ESP32S3 Dev Module
- Select the correct COM port
- Install all required libraries (see above)
- Click Upload
Open Serial Monitor at 115200 baud. You should see:
[BOOT] Solar Planner Starting...
[OLED] OK
[PZEM] Serial ports initialized
[AP] IP: 192.168.4.1
[STA] Connecting to: YourWiFi
[WEB] Server started on port 80
[BOOT] Setup complete β entering loop
[FIREBASE] WiFi up, initializing...
[FIREBASE] Sign-up OK
[FIREBASE] Data pushed OK
The display cycles through 6 pages (4 seconds each):
| Page | Source | Shows |
|---|---|---|
| 0 | π Home | Power (W) + Voltage (V) |
| 1 | π Home | Current (A) + Frequency (Hz) |
| 2 | π Home | Energy (kWh) + Power Factor |
| 3 | β‘ Grid | Power (W) + Voltage (V) |
| 4 | β‘ Grid | Current (A) + Frequency (Hz) |
| 5 | β‘ Grid | Energy (kWh) + Power Factor |
The navbar shows: source label, page indicator dots, LIVE tag, and a blinking WiFi icon when connected.
When connected to the ESP32's soft-AP (Solar_Planner_AP) β or same LAN β open:
http://192.168.4.1
The dashboard shows both channels in real time (auto-refreshes every 2 seconds):
| Metric | Home π | Grid β‘ |
|---|---|---|
| Voltage | β | β |
| Current | β | β |
| Active Power | β | β |
| Total Energy | β | β |
| Frequency | β | β |
| Power Factor | β | β |
JSON API also available at http://192.168.4.1/api/data.
Data is pushed to path /solar_monitor/live every 5 seconds:
{
"home": {
"connected": true,
"voltage": 228.4,
"current": 1.234,
"power": 281.7,
"energy": 0.045,
"frequency": 50.0,
"pf": 0.99
},
"grid": {
"connected": true,
"voltage": 230.1,
"current": 2.100,
"power": 483.2,
"energy": 0.091,
"frequency": 50.0,
"pf": 0.98
},
"updatedAt": 123456789
}| Constant | Default | Purpose |
|---|---|---|
READ_INTERVAL |
2000 ms | PZEM sensor polling rate |
DISPLAY_INTERVAL |
1000 ms | OLED refresh rate |
PAGE_INTERVAL |
4000 ms | OLED page rotation speed |
FIREBASE_INTERVAL |
5000 ms | Firebase push frequency |
BLINK_INTERVAL |
600 ms | WiFi icon blink period |
SolarPlanner-DualEnergyMonitor/
βββ doublepzemwithdisplayfirebase/ β Arduino sketch folder
β βββ doublepzemwithdisplayfirebase.ino β Main sketch
β βββ secrets.h β [GITIGNORED] Your credentials
βββ docs/ β All media & diagrams
β βββ demo.mp4 β Live demo video
β βββ circuit_diagram.png β Full circuit diagram
β βββ dual_pzem_circuit.png β Dual PZEM wiring
β βββ architecture_diagram.png β System architecture
β βββ production_photo.png β Hardware build photo
β βββ pzem004t_pinout.png β PZEM-004T pinout reference
β βββ sketch.jpeg β Initial design sketch
βββ Circuit Diagram.drawio β Editable DrawIO source
βββ secrets.h.example β β
Safe credentials template
βββ .gitignore β Excludes secrets.h
βββ README.md β This file
This hardware node feeds data into the SolarPlanner dashboard β a full solar energy management system that tracks generation, consumption, grid import/export, and battery state.
Caution
This project involves mains AC voltage (230V). Incorrect wiring can cause electric shock, fire, or equipment damage.
- Always work with power OFF and unplugged
- Use properly rated insulated wires and connectors
- House the electronics in a non-conductive enclosure
- The PZEM-004T has built-in isolation β use its provided terminal block connections
MIT License β feel free to use, modify, and build upon this project.
Built with β as part of Final Year Project β 2025/26





