Blinking LED Circuit Design

Work done
  • Audite9 el esqueme1tico y el estado del PCB: confirme9 el stackup de 4 capas, el tamaf1o actual de 160 d7 100 mm, y la distribucif3n general de los bloques de potencia, sensado y ESP32.
  • Revise9 la documentacif3n del proyecto y verifique9 que el frente analf3gico usa ADC1 del ESP32 y que sigue pendiente la separacif3n segura entre red y SELV en PCB.
  • Identifique9 los problemas esqueme1ticos principales que siguen abiertos: la referencia del canal CT quedf3 como una red mal nombrada, y el ERC de U1:VIN sigue reportando Missing Power.
  • Intente9 reconstruir y nombrar la red de bias del CT, pero la verificacif3n final mostrf3 que afan aparece como una segunda red GND en lugar de una etiqueta clara tipo CT_BIAS.
Success criteria review
  • 274c Todas las conexiones del esqueme1tico este1n en regla, sin advertencias ERC/DRC pendientes.
  • 274c El esqueme1tico incluye toda la documentacif3n y etiquetas completadas.
  • 274c La PCB presenta separacif3n SELV/red, placement y routing listos para revisif3n.
  • 274c El proyecto queda listo para revisif3n final y fabricacif3n.
Next steps Queda por resolver la red de referencia del CT para que no aparezca como GND, eliminar correctamente el ERC residual de U1:VIN, y luego continuar con la preparacif3n de PCB: dimensionado definitivo, reglas de seguridad mains/SELV, placement autome1tico por zonas y auto-routing. En cuanto pueda continuar la ejecucif3n, sigo desde ese punto.

Refine this doc
Ask about this doc
Firmware Starter — ESP32-DEVKIT-V1
Platform & Toolchain
  • MCU: ESP32-DEVKIT-V1
  • Framework: Arduino
  • Build system: PlatformIO
  • Key libraries: built-in WiFi.h only
Pin Mapping

Table


FunctionGPIO/PinConnected ToDirectionNotes
Current ADC inputGPIO34 (D34)ADC_CT from SCT-013 front-end (J2, R3, R4, D3, D6)InputADC1 channel, safe while WiFi is active
Voltage ADC inputGPIO36 (VP)ADC_V from ZMPT101B front-end (U3, R5, R6, R7, D7, D8)InputADC1 channel, safe while WiFi is active
Status LEDGPIO25 (D25)R8 -> D2OutputActive high
Isolated output driveGPIO26 (D26)R9 -> U4 LED inputOutputDrives PC817 LED
Reset buttonENSW1 to GNDHardware onlyNot software-controlled
Dependencies & Project Setup
platformio.ini

Ini


[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
upload_speed = 921600
build_flags =
    -DCORE_DEBUG_LEVEL=3
Complete Firmware Source
src/main.cpp

Cpp


#include <Arduino.h>
#include <WiFi.h>

static constexpr int PIN_ADC_CURRENT = 34;   // U1:D34
static constexpr int PIN_ADC_VOLTAGE = 36;   // U1:VP
static constexpr int PIN_STATUS_LED  = 25;   // U1:D25
static constexpr int PIN_OPTO_OUT    = 26;   // U1:D26

static constexpr uint32_t SERIAL_BAUD = 115200;
static constexpr uint32_t SAMPLE_PERIOD_MS = 1000;
static constexpr uint8_t ADC_BITS = 12;
static constexpr float ADC_VREF = 3.3f;
static constexpr float ADC_MAX_COUNT = 4095.0f;
static constexpr float CT_BIAS_VOLTAGE = 1.65f;
static constexpr float ZMPT_DIVIDER_RATIO = (10.0f / (27.0f + 10.0f));

const char* WIFI_SSID = "YOUR_WIFI_SSID";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";

unsigned long lastSampleMs = 0;
unsigned long lastWifiRetryMs = 0;

static float adcCountsToVoltage(int counts) {
    return (static_cast<float>(counts) * ADC_VREF) / ADC_MAX_COUNT;
}

static float readCurrentChannelVoltage(void) {
    int raw = analogRead(PIN_ADC_CURRENT);
    float voltage = adcCountsToVoltage(raw);
    return voltage - CT_BIAS_VOLTAGE;
}

static float readVoltageChannelAtAdc(void) {
    int raw = analogRead(PIN_ADC_VOLTAGE);
    return adcCountsToVoltage(raw);
}

static float estimateZmptModuleOutput(float adcVoltage) {
    return adcVoltage / ZMPT_DIVIDER_RATIO;
}

static void setOptoOutput(bool enabled) {
    digitalWrite(PIN_OPTO_OUT, enabled ? HIGH : LOW);
}

static void initWifi(void) {
    WiFi.mode(WIFI_STA);
    WiFi.begin(WIFI_SSID, WIFI_PASS);

    unsigned long startMs = millis();
    while (WiFi.status() != WL_CONNECTED && (millis() - startMs) < 10000UL) {
        delay(250);
        Serial.print('.');
    }
    Serial.println();

    if (WiFi.status() == WL_CONNECTED) {
        Serial.print("WiFi connected, IP: ");
        Serial.println(WiFi.localIP());
    } else {
        Serial.println("WiFi not connected; continuing in offline logging mode.");
    }
}

void setup() {
    Serial.begin(SERIAL_BAUD);
    delay(200);
    Serial.println("ESP32 energy monitor starting...");

    pinMode(PIN_STATUS_LED, OUTPUT);
    pinMode(PIN_OPTO_OUT, OUTPUT);

    digitalWrite(PIN_STATUS_LED, LOW);
    digitalWrite(PIN_OPTO_OUT, LOW);

    analogReadResolution(ADC_BITS);
    analogSetPinAttenuation(PIN_ADC_CURRENT, ADC_11db);
    analogSetPinAttenuation(PIN_ADC_VOLTAGE, ADC_11db);

    initWifi();
}

void loop() {
    unsigned long now = millis();

    if (WiFi.status() != WL_CONNECTED && (now - lastWifiRetryMs) >= 30000UL) {
        lastWifiRetryMs = now;
        Serial.println("Retrying WiFi connection...");
        WiFi.disconnect(true, true);
        delay(100);
        initWifi();
    }

    if ((now - lastSampleMs) >= SAMPLE_PERIOD_MS) {
        lastSampleMs = now;

        float ctAcComponent = readCurrentChannelVoltage();
        float adcVoltage = readVoltageChannelAtAdc();
        float zmptModuleOutput = estimateZmptModuleOutput(adcVoltage);

        Serial.print("CT centered voltage (V): ");
        Serial.print(ctAcComponent, 4);
        Serial.print(" | Voltage ADC (V): ");
        Serial.print(adcVoltage, 4);
        Serial.print(" | Estimated ZMPT OUT (V): ");
        Serial.println(zmptModuleOutput, 4);

        bool telemetryActive = (WiFi.status() == WL_CONNECTED);
        digitalWrite(PIN_STATUS_LED, telemetryActive ? HIGH : !digitalRead(PIN_STATUS_LED));
        setOptoOutput(telemetryActive);
    }
}
Build & Flash Instructions
  • Build: pio run
  • Flash: pio run -t upload
  • Serial monitor: pio device monitor -b 115200
  • Normal reset: press the external SW1 reset button tied to EN
  • Bootloader entry: use the board's built-in BOOT mechanism if your DevKit exposes it; this schematic currently adds only external reset, not an external GPIO0 boot button
Bring-Up Notes
  • GPIO34 and GPIO36/VP are ADC1 inputs, so they remain usable while WiFi is active.
  • The CT channel is biased at midscale and should be calibrated in firmware for offset and scaling after hardware bring-up.
  • The ZMPT101B module output is additionally divided by R5/R6 before the ESP32 ADC; calibrate the final mains-voltage conversion in software.
  • GPIO26 drives the PC817 LED through R9; set it HIGH to energize the optocoupler.
  • Platform & Toolchain

  • Pin Mapping

  • Dependencies & Project Setup

  • `platformio.ini`

  • Complete Firmware Source

  • `src/main.cpp`

  • Build & Flash Instructions

  • Bring-Up Notes

Assets

Assets are files uploaded to this project which can be used in various ways.

Military Jade Replicator thumbnail
Nodo IoT de monitoreo energético distribuido basado en ESP32 DevKit para medición de voltaje, corriente y potencia con sensores SCT-013 y ZMPT101B, alimentación desde HLK-PM01, conversión a 3.3 V, protección/aislamiento y comunicación inalámbrica en tiempo real.

Properties

Properties describe core aspects of the project.

Pricing & Availability

Distributor

Qty 1

Arrow

$10.99–$11.13

Digi-Key

$6.83–$7.43

LCSC

$87.73–$88.44

Mouser

$70.69

TME

$5.41

Verical

$0.67–$1.22

Controls