ESP32 Development Board

Setup and configure ESP32 as the main controller for Gridova IoT system

ESP32 Development Board

Why ESP32?

ESP32 offers dual-core processing, built-in WiFi/Bluetooth, multiple GPIO pins, and low power consumption - perfect for IoT applications like Gridova.

ESP32 Specifications

Key Features

Processor

  • • Dual-core Xtensa 32-bit LX6
  • • Clock frequency up to 240 MHz
  • • 520 KB SRAM, 4 MB Flash

Connectivity

  • • WiFi 802.11 b/g/n (2.4 GHz)
  • • Bluetooth 4.2 & BLE
  • • Multiple communication protocols

GPIO & Interfaces

  • • 34 programmable GPIO pins
  • • SPI, I2C, UART interfaces
  • • 12-bit ADC, 8-bit DAC

Power

  • • Operating voltage: 3.3V
  • • Input voltage: 5V via USB/Vin
  • • Deep sleep mode support

Arduino IDE Setup

1. Install Arduino IDE

Download and install Arduino IDE 1.8.x or 2.x from the official website.

Download Linkbash
https://www.arduino.cc/en/software

2. Add ESP32 Board Manager URL

Open Arduino IDE, go to File → Preferences, and add this URL:

Board Manager URLtext
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

3. Install ESP32 Board

Go to Tools → Board → Boards Manager, search for "esp32" and install.

4. Select Board and Port

  • Board: ESP32 Dev Module
  • Upload Speed: 921600
  • Port: Select your COM port (e.g., COM3, COM5)

Required Libraries

Install these libraries via Sketch → Include Library → Manage Libraries:

WiFi & HTTP

  • WiFi.h - Built-in WiFi library
  • HTTPClient.h - For REST API calls
  • WebServer.h - Web server functionality

PZEM Sensor Communication

  • PZEM004Tv30.h - PZEM sensor library
  • HardwareSerial.h - For UART communication

Data & Time

  • ArduinoJson.h - JSON parsing
  • NTPClient.h - Network time sync

Basic WiFi Connection Code

wifi_basic.inocpp
#include <WiFi.h>

// WiFi credentials
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

void setup() {
  Serial.begin(115200);
  delay(1000);
  
  // Connect to WiFi
  Serial.println("Connecting to WiFi...");
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  
  Serial.println("");
  Serial.println("WiFi connected!");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  // Check WiFi connection
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("WiFi disconnected. Reconnecting...");
    WiFi.reconnect();
  }
  delay(10000);
}

HTTP POST Request Example

Send sensor data to Gridova backend API:

http_post_example.inocpp
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>

const char* serverUrl = "https://api.gridova.com/sensor-data";
const char* apiKey = "YOUR_API_KEY";

void sendSensorData(float voltage, float current, float power) {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    
    http.begin(serverUrl);
    http.addHeader("Content-Type", "application/json");
    http.addHeader("Authorization", "Bearer " + String(apiKey));
    
    // Create JSON payload
    StaticJsonDocument<256> doc;
    doc["device_id"] = "ESP32_001";
    doc["voltage"] = voltage;
    doc["current"] = current;
    doc["power"] = power;
    doc["timestamp"] = millis();
    
    String jsonString;
    serializeJson(doc, jsonString);
    
    // Send POST request
    int httpResponseCode = http.POST(jsonString);
    
    if (httpResponseCode > 0) {
      Serial.printf("HTTP Response: %d\n", httpResponseCode);
      String response = http.getString();
      Serial.println(response);
    } else {
      Serial.printf("Error: %s\n", http.errorToString(httpResponseCode).c_str());
    }
    
    http.end();
  }
}

void loop() {
  // Read sensor values (example)
  float voltage = 220.5;
  float current = 2.8;
  float power = voltage * current;
  
  sendSensorData(voltage, current, power);
  delay(5000); // Send every 5 seconds
}

GPIO Pin Configuration

Recommended GPIO pins for Gridova hardware connections:

ComponentESP32 PinFunction
PZEM TXGPIO 16 (RX2)UART receive from PZEM
PZEM RXGPIO 17 (TX2)UART transmit to PZEM
Relay 1GPIO 25Digital output for relay control
Relay 2GPIO 26Digital output for relay control
Status LEDGPIO 2Built-in LED indicator
ButtonGPIO 0Boot/flash button (input)

Important Notes

  • Avoid using GPIO 6-11 (connected to flash memory)
  • GPIO 34-39 are input-only pins
  • Some pins have pull-up/pull-down resistors by default
  • Always use 3.3V logic level for GPIO communication

Troubleshooting

Upload Failed / Port Not Found
  • Install CP210x or CH340 USB driver
  • Hold BOOT button while uploading
  • Try different USB cable (some are power-only)
  • Check device manager for COM port
Brown-out Detector Error
  • Use external 5V power supply (not just USB)
  • Check power supply current rating (min 1A)
  • Add 100µF capacitor near power pins
WiFi Connection Issues
  • Ensure 2.4 GHz WiFi band (ESP32 doesn't support 5 GHz)
  • Check SSID and password spelling
  • Move closer to router during testing
  • Add WiFi.reconnect() in case of disconnection

Next Steps

Connect PZEM Sensor
Learn how to wire and read data from PZEM-004T energy sensor
Setup Relay Control
Configure relay module for remote power switching
Complete Wiring Diagram
See full system wiring with all components connected