Bloqueo Fuente 12V
Generic Testpoint de un solo pad y los reconecté a sus redes originales: GND, 3V3, 5V_SYS, USB D±, ESP_EN, ESP_BOOT, ADC_AC_VOLTAGE, ADC_CURRENT, RELAY_SET_GPIO y RELAY_RESET_GPIO.U2 = IRM-30-12 de 12 V/2.5 A, F2 = 2 A, J7, U6, C15–C17. Eso no cumple el requisito de salida auxiliar 12 V/3 A.power-12v-production-decision.IRM-30-12, F2 2A, J7, U6, C15–C17) o reemplazarlo solo con un módulo real 40–45 W con footprint confiable.power-12v-production-decision documentando que ZMPT101B se mantiene y que 12 V/3 A queda bloqueado hasta disponer de parte/footprint certificado.Table
| Function | GPIO | Net |
|---|---|---|
| Relay SET pulse | 4 | RELAY_SET_GPIO |
| Relay RESET pulse | 5 | RELAY_RESET_GPIO |
| WiFi/status LED | 6 | LED_WIFI_GPIO |
| Relay/status LED | 7 | LED_RELAY_GPIO |
| I2C SCL | 8 | I2C_SCL |
| I2C SDA | 9 | I2C_SDA |
| ACS732 overcurrent fault | 10 | ACS_FAULT |
| Current ADC | 1 | ADC_CURRENT |
| AC voltage ADC | 2 | ADC_AC_VOLTAGE |
| UART TX expansion | TXD0 | UART0_TX_EXP |
| UART RX expansion | RXD0 | UART0_RX_EXP |
| BOOT | 0 | ESP_BOOT |
Ini
[env:esp32-s3] platform = espressif32 board = esp32-s3-devkitc-1 framework = arduino monitor_speed = 115200 upload_speed = 921600 build_flags = -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1
Cpp
#include <Arduino.h> #include <Wire.h> #include <WiFi.h> #define RELAY_SET_PIN 4 #define RELAY_RESET_PIN 5 #define LED_WIFI_PIN 6 #define LED_RELAY_PIN 7 #define I2C_SCL_PIN 8 #define I2C_SDA_PIN 9 #define ACS_FAULT_PIN 10 #define ADC_CURRENT_PIN 1 #define ADC_AC_VOLTAGE_PIN 2 #define TMP102_ADDR 0x48 #define RELAY_PULSE_MS 50 #define SAMPLE_INTERVAL_MS 1000 const char* WIFI_SSID = "YOUR_SSID"; const char* WIFI_PASSWORD = "YOUR_PASSWORD"; bool relayOn = false; uint32_t lastSample = 0; void pulseRelay(bool turnOn) { const int pin = turnOn ? RELAY_SET_PIN : RELAY_RESET_PIN; digitalWrite(pin, HIGH); delay(RELAY_PULSE_MS); digitalWrite(pin, LOW); relayOn = turnOn; digitalWrite(LED_RELAY_PIN, relayOn ? HIGH : LOW); } bool readTMP102(float &tempC) { Wire.beginTransmission(TMP102_ADDR); Wire.write(0x00); if (Wire.endTransmission(false) != 0) return false; if (Wire.requestFrom(TMP102_ADDR, 2) != 2) return false; int16_t raw = (Wire.read() << 4) | (Wire.read() >> 4); if (raw & 0x800) raw |= 0xF000; tempC = raw * 0.0625f; return true; } float readAdcVolts(int pin) { uint16_t raw = analogRead(pin); return (raw / 4095.0f) * 3.3f; } float estimateLoadCurrentA() { float vadc = readAdcVolts(ADC_CURRENT_PIN); float sensorVout = vadc * 1.5f; // R22=10k, R23=20k divider return (sensorVout - 2.5f) / 0.050f; // ACS732-40AB: 50 mV/A typ } float readAcVoltageAdcVolts() { return readAdcVolts(ADC_AC_VOLTAGE_PIN); // Calibration required for RMS mains voltage } void initWiFi() { WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); uint8_t tries = 0; while (WiFi.status() != WL_CONNECTED && tries++ < 20) { digitalWrite(LED_WIFI_PIN, !digitalRead(LED_WIFI_PIN)); delay(250); } digitalWrite(LED_WIFI_PIN, WiFi.status() == WL_CONNECTED ? HIGH : LOW); } void setup() { Serial.begin(115200); delay(300); pinMode(RELAY_SET_PIN, OUTPUT); pinMode(RELAY_RESET_PIN, OUTPUT); pinMode(LED_WIFI_PIN, OUTPUT); pinMode(LED_RELAY_PIN, OUTPUT); pinMode(ACS_FAULT_PIN, INPUT_PULLUP); digitalWrite(RELAY_SET_PIN, LOW); digitalWrite(RELAY_RESET_PIN, LOW); digitalWrite(LED_RELAY_PIN, LOW); analogReadResolution(12); Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN); initWiFi(); Serial.println("ESP32-S3 IoT Relay Controller ready"); } void loop() { if (millis() - lastSample >= SAMPLE_INTERVAL_MS) { lastSample = millis(); float tempC = NAN; bool tempOk = readTMP102(tempC); float currentA = estimateLoadCurrentA(); float acAdc = readAcVoltageAdcVolts(); bool fault = digitalRead(ACS_FAULT_PIN) == LOW; Serial.printf("relay=%d temp=%s%.2fC current=%.2fA ac_adc=%.3fV fault=%d wifi=%d\n", relayOn, tempOk ? "" : "ERR ", tempOk ? tempC : NAN, currentA, acAdc, fault, WiFi.status() == WL_CONNECTED); if (fault || (tempOk && tempC > 85.0f)) { pulseRelay(false); Serial.println("Safety trip: relay reset"); } } if (WiFi.status() != WL_CONNECTED) initWiFi(); }
Bash
pio run pio run -t upload pio device monitor
Platform & Toolchain
Pin Mapping
platformio.ini
Complete Firmware Source
Build & Flash