Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

⚑ SolarPlanner – Dual Energy Monitor

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.


πŸ“½οΈ Demo

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

πŸ—οΈ System Architecture

System Architecture Diagram

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

πŸ”Œ Hardware Components

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

πŸ“Œ Pin Wiring (ESP32-S3)

OLED Display (SSD1306 β€” IΒ²C)

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-004T #1 β€” Home Load

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-004T #2 β€” Grid (WAPDA)

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

Status LED

Component GPIO Notes
LED (+ resistor) GPIO 2 Solid = WiFi connected, Blink = connecting

πŸ”§ PZEM-004T Pinout

PZEM-004T v3.0 Pinout

⚠️ 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.


πŸ“ Circuit Diagram

Circuit Diagram

Dual PZEM Wiring Diagram

The editable source (DrawIO) is included: Circuit Diagram.drawio


πŸ“Έ Hardware Build

Production Hardware Build

Initial Hand Sketch


πŸ“¦ Required Libraries

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

πŸš€ Setup Guide

1. Clone the Repository

git clone https://github.com/YOUR_USERNAME/SolarPlanner-DualEnergyMonitor.git
cd SolarPlanner-DualEnergyMonitor

2. Create Your Secrets File

# Copy the example template
cp secrets.h.example doublepzemwithdisplayfirebase/secrets.h

Then 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/"

3. Firebase Setup

  1. Go to Firebase Console β†’ Create Project
  2. Enable Realtime Database (start in test mode)
  3. Go to Project Settings β†’ General β†’ copy the Web API Key
  4. Copy the Database URL from the RTDB dashboard
  5. Paste both into your secrets.h

4. Open in Arduino IDE

  • Open doublepzemwithdisplayfirebase/doublepzemwithdisplayfirebase.ino
  • Select board: ESP32S3 Dev Module
  • Select the correct COM port
  • Install all required libraries (see above)
  • Click Upload

5. Verify It's Running

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

πŸ“Š OLED Display Pages

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.


🌐 Web Dashboard

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.


πŸ”₯ Firebase RTDB Schema

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
}

⏱️ Timing Configuration

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

πŸ—‚οΈ Repository Structure

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

πŸ”— Part of SolarPlanner

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.

πŸ”— SolarPlanner Main Repository


⚠️ Safety Notice

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

πŸ“„ License

MIT License β€” feel free to use, modify, and build upon this project.


Built with β˜• as part of Final Year Project β€” 2025/26

About

A real-time ESP32-S3 dual-channel energy monitoring system for Home Load and Grid (WAPDA), featuring dual PZEM-004T sensors, Firebase Realtime Database, SSD1306 OLED display, and a built-in web dashboard.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages