Blinking LED Circuit Design


Work done
  • Audite9 el estado actual del proyecto y revalide9 ERC/DRC.
  • Confirme9 el stackup actual de 4 capas y que la PCB sigue en 160 d7 100 mm sin rulesets expledcitos de seguridad.
  • Verifique9 la conectividad de los bloques credticos del esqueme1tico: U1, U2, U3, PS1, J2, R10 y C9.
  • Identifique9 los pendientes concretos que bloquean dejarlo listo para revisif3n final.
Success criteria review
  • d8 El esqueme1tico todaveda tiene 1 ERC pendiente: U1:VIN sin alimentacif3n.
  • d8 Sigue existiendo una net sin nombre entre R1, R2, R3, C7 y J2, que conviene nombrar y revisar.
  • d8 La PCB afan tiene 94 DRC: 79 airwires, 14 floating copper y 1 capa con mfaltiples fills.
  • d8 No hay reglas de PCB expledcitas para separacif3n SELV vs red, anchos, clearances o zoning de seguridad.
  • d8 No pude completar el placement final ni el auto-routing hasta dejar la placa lista para fabricacif3n.
Next steps
  • Corregir primero el esqueme1tico: resolver la alimentacif3n de U1:VIN y renombrar/verificar la net del bias del CT.
  • Despue9s, configurar reglas PCB de seguridad: clearance red-SELV, clasificacif3n de nets y fills.
  • Luego, continuar con board sizing/placement por zonas y auto-routing para eliminar airwires y revisar manufacturabilidad.
  • Si quieres, en la siguiente ejecucif3n puedo retomar exactamente desde este punto y seguir con la preparacif3n de la PCB.
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.

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