Hardware
Hardware Integration
Learn how to set up and integrate ESP32, PZEM-004T sensor, and relay modules for real-time electricity monitoring and control
Safety Warning
This project involves working with high voltage (220V AC). Always disconnect power before making connections. If you're not confident working with electricity, consult a licensed electrician.
Hardware Overview
Gridova's hardware stack consists of three main components that work together to monitor electricity consumption and control power remotely.
1. ESP32 Microcontroller
The ESP32 serves as the brain of the system, responsible for:
- Reading data from PZEM-004T sensor via UART
- Controlling relay modules via GPIO pins
- Connecting to WiFi network
- Sending data to Flutter app via REST API
- Providing real-time updates via WebSocket
Key Specifications:
- • 32-bit dual-core processor (up to 240 MHz)
- • Built-in WiFi (802.11 b/g/n) and Bluetooth
- • 34 GPIO pins (some with special functions)
- • 3 UART interfaces
- • Operating voltage: 3.3V (5V tolerant on some pins)
2. PZEM-004T v3.0 Sensor
An accurate energy monitoring module that measures:
- Voltage: 80-260V AC (±0.5% accuracy)
- Current: 0-100A (±0.5% accuracy)
- Power: Up to 23kW
- Energy: Cumulative kWh consumption
- Frequency: 45-65Hz
- Power Factor: 0.00-1.00
Communication:
Uses TTL UART (5V) with Modbus-RTU protocol. Baud rate: 9600 bps
3. Relay Module
Electronically controlled switch for power management:
- Available in 1, 2, 4, or 8 channel configurations
- Control voltage: 5V DC (from ESP32)
- Load capacity: 10A @ 250V AC or 30V DC
- Optocoupler isolation for safety
- Active LOW trigger (LOW = ON, HIGH = OFF)
Safety Features:
- • Optical isolation between control and load circuits
- • LED indicators for each relay
- • Screw terminals for secure connections
Complete System Diagram
Required Components
| Component | Specification | Quantity | Notes |
|---|---|---|---|
| ESP32 Dev Board | 30-pin, WiFi+BT | 1 | Any variant (WROOM, WROVER) |
| PZEM-004T v3.0 | 100A version | 1 per room | With current transformer (CT) |
| Relay Module | 1-4 channel, 5V | 1 | Choose based on rooms |
| Power Supply | 5V, 2A min | 1 | For ESP32 and relays |
| Jumper Wires | Male-Female | 10-15 | For connections |
| Breadboard | 830 points | 1 | For prototyping (optional) |
| Enclosure | Plastic box | 1 | For final installation |
Power Requirements
Live Sensor Data Preview
Example of real-time data visualization (simulated):
Basic Arduino Code
Here's a minimal example to get started with reading PZEM sensor:
basic_pzem_test.inocpp
#include <PZEM004Tv30.h>
// PZEM on Serial2 (GPIO16=RX, GPIO17=TX)
PZEM004Tv30 pzem(Serial2, 16, 17);
void setup() {
Serial.begin(115200);
Serial.println("Gridova - PZEM Test");
}
void loop() {
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)) {
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("PF: "); Serial.println(pf);
} else {
Serial.println("Error reading PZEM");
}
delay(2000);
}For complete firmware code with WiFi, API, and relay control, see the ESP32 Setup Guide.
