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.
ESP32
Main microcontroller with WiFi & Bluetooth
PZEM-004T
Energy monitoring sensor (80-260V, 0-100A)
Relay Module
Power control switch (1-4 channel, 5V/220V)

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

ESP32 to PZEM-004T Wiring Diagram
Connect your ESP32 to PZEM sensor and relay module
ESP32GPIO16 (RX2)GPIO17 (TX2)5VGNDGPIO25PZEM-004TRXTX5VGNDRelay ModuleINVCC (5V)GNDCOM/NO/NC5V PowerSupplyTX2 → RXRX2 → TXGPIO25 → IN

Pin Connections:

ESP32 to PZEM-004T
GPIO16 (RX2)PZEM TX
GPIO17 (TX2)PZEM RX
5VPZEM 5V
GNDPZEM GND
ESP32 to Relay
GPIO25Relay IN
5VRelay VCC
GNDRelay GND

View detailed wiring instructions →

Required Components

ComponentSpecificationQuantityNotes
ESP32 Dev Board30-pin, WiFi+BT1Any variant (WROOM, WROVER)
PZEM-004T v3.0100A version1 per roomWith current transformer (CT)
Relay Module1-4 channel, 5V1Choose based on rooms
Power Supply5V, 2A min1For ESP32 and relays
Jumper WiresMale-Female10-15For connections
Breadboard830 points1For prototyping (optional)
EnclosurePlastic box1For final installation

Power Requirements

Recommended Power Supply

Option 1: USB Power Adapter (Recommended for Testing)

  • 5V, 2A USB adapter
  • Connect to ESP32 via micro-USB
  • Simple and safe for development

Option 2: AC-DC Converter (For Production)

  • 220V AC to 5V DC converter module
  • Output: 5V, 3A
  • Integrated with main installation
  • No external power adapter needed
Calculate total power consumption: ESP32 (500mA) + Relays (70mA × number of channels). Choose power supply with 50% headroom.

Live Sensor Data Preview

Example of real-time data visualization (simulated):

Real-time Sensor Data Preview

Live monitoring of electrical parameters (simulated data)

Loading chart...

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.