Skip to content

Instantly share code, notes, and snippets.

@askpatrickw
Created September 29, 2024 06:00
Show Gist options
  • Select an option

  • Save askpatrickw/c79399870e2c0495a869ea8b6b033884 to your computer and use it in GitHub Desktop.

Select an option

Save askpatrickw/c79399870e2c0495a869ea8b6b033884 to your computer and use it in GitHub Desktop.
ESP32-Based Relay Board with Power Monitoring and PoE Integration

ESP32-Based Relay Board with Power Monitoring and PoE Integration

Objective: Design and build a custom relay board using the ESP32 microcontroller with integrated Power over Ethernet (PoE) functionality. The board will control 8 relays, each capable of handling up to 10A at 24VDC, and include current monitoring for each relay using ACS712 sensors. The system will be compatible with ESPHome for easy integration with Home Assistant.

Project Requirements:

1. Functional Requirements:

  • Relay Control:

    • 8 relays, each rated for 16A at 250VAC and 10A at 24VDC.
    • Relay model: G5RLU-1A-E DC3 (Omron Electronics), with a 3V coil voltage.
    • Controlled via the ESP32 microcontroller.
    • Maximum Load: 10A per circuit at 24VDC.
  • Power Monitoring:

    • Each relay circuit will include an ACS712 current sensor for real-time current monitoring, calibrated for up to 10A.
    • The current sensors will be configured and calibrated for accurate power measurements in ESPHome.
  • PoE Power Supply:

    • Power input through an Ethernet RJ45 connector (TRP Connector B.V. 2250506-1).
    • PoE module: Silvertel AG9903-MTB, providing 3.3V output for the ESP32 and relays.
  • Microcontroller:

    • ESP32-WROOM-32 or ESP32-WROVER module with Wi-Fi and Bluetooth support.
    • Programmed using ESPHome for integration with Home Assistant.
  • Relay Driver:

    • ULN2803A 8-channel Darlington array for driving the relay coils.

2. Technical Specifications:

  • Input Voltage: 36V - 57V DC from the PoE module.
  • Output Voltage: 3.3V DC, up to 2A (provided by the PoE module).
  • Relay Coil Voltage: 3V DC, 200mA per relay.
  • Load Voltage: 24VDC, maximum current per circuit: 10A.
  • Current Measurement Range: 0A - 10A per relay (using ACS712 sensors).
  • Communication Protocol: Wi-Fi (802.11 b/g/n) for ESP32.

3. PCB Design Considerations:

  • PCB Layout:

    • Compact design with all components securely mounted.
    • Proper trace width for high-current paths (at least 2mm) to handle up to 10A per circuit.
    • Adequate isolation between high-voltage (24VDC) and low-voltage (3.3V) sections.
  • Component Placement:

    • PoE module and RJ45 connector placed close together to minimize power loss.
    • Relays and current sensors placed with sufficient spacing to reduce interference.
  • Ground Planes:

    • A solid ground plane for noise suppression and signal integrity.

4. Software Requirements:

  • ESPHome Configuration:

    • Define GPIO pins for each relay.
    • Configure each ACS712 sensor for accurate current monitoring.
    • Implement calibration logic for the current sensors based on the 10A max load.
  • Integration with Home Assistant:

    • Each relay and sensor will be configured as an entity in Home Assistant.
    • Ability to control relays and monitor current consumption remotely.

5. Deliverables:

  • Schematic Design: Detailed schematic diagram of the complete system.
  • PCB Layout: Optimized PCB design files in Gerber format.
  • BOM (Bill of Materials): Complete list of components with part numbers and quantities.
  • ESPHome Configuration Files: YAML configuration for ESPHome with all relays and sensors defined.
  • Prototype Board: Fully assembled and tested prototype for evaluation.

6. Additional Notes:

  • External Fusing: No internal fuses will be included on the board. It is assumed that each load will be fused externally using a separate fuse block.
  • Flyback Diodes: For inductive loads (e.g., motors or solenoids), flyback diodes should be added externally to protect the relay contacts from voltage spikes.
@askpatrickw
Copy link
Author

GPT5Pro Notes

  1. Relay type mismatch (latching vs non‑latching)
    Verify the exact Omron G5RLU-1A-E DC3 variant is monostable vs latching. If it’s latching, the current ULN2803A low‑side drive scheme won’t support the required reverse/reset actuation.

  2. Relay coil drive headroom with ULN2803A
    Validate coil pull‑in at worst case: 3.3V supply – ULN VCE(sat) may leave the 3V coil under‑driven. Confirm pull‑in margin across temperature and supply droop.

  3. PoE power budget is too tight at “all relays on”
    8 relays × ~200mA = ~1.6A, leaving little margin for ESP32 + sensors + transients. Recheck AG9903 output capability vs worst case and consider power sequencing / alternative rail strategy.

  4. Driver thermal dissipation (ULN2803A)
    At ~200mA/channel, ULN2803A dissipates significant heat (especially with 8 channels on). Confirm package thermal limits and temperature rise; consider MOSFET drivers if needed.

  5. ACS712 supply voltage incompatibility
    ACS712 is typically a 5V part. If you only have 3.3V, either add a 5V rail (and handle output scaling) or switch to a 3.3V-capable sensor (preferred).

  6. ACS712 output range vs ESP32 ADC
    If powered at 5V, ACS712 zero-current output is ~2.5V and peaks can exceed 3.3V depending on variant/current direction. Ensure ADC attenuation/scaling/dividers prevent overvoltage and preserve resolution.

  7. ESP32 ADC channel selection (Wi‑Fi conflict)
    Ensure all 8 current sensors land on ADC1 pins only. ADC2 readings become unreliable when Wi‑Fi is active.

  8. ESP32 boot/strapping pin hazards
    Don’t drive relay inputs from strapping pins or pins that glitch at boot. Ensure relays default OFF on reset/boot with proper pulldowns and safe pin mapping.

  9. PCB trace width/copper weight is under-specified
    “2mm for 10A” is likely insufficient on 1oz copper. Recalculate per IPC‑2152 assumptions; use wide pours, short paths, 2oz copper, via stitching, and avoid bottlenecks.

  10. Connector ratings (per-channel and aggregate)
    Verify terminal blocks and the 24V input connector are rated for the real currents. Worst case aggregate could be very high; design should assume realistic max or segment feeds.

  11. PoE PD front-end implementation details
    Confirm the RJ45/magnetics/center-tap wiring and required bridge rectifiers / input filtering exactly match the AG9903 reference design. Layout and creepage across the isolation boundary matter.

  12. Power rail stability / brownout risk
    Relay activation + ESP32 Wi‑Fi TX can cause droop. Add/verify bulk capacitance near PoE output and local decoupling near ESP32; validate with scope under worst-case switching.

  13. Isolation/grounding architecture not fully defined
    Decide explicitly: keep 24V load domain isolated from logic (recommended) vs tie grounds. Ensure layout doesn’t accidentally bridge the isolation and that measurement references remain valid.

  14. Thermal design at sustained duty
    Worst-case heat sources: relay coils (multi-watt total), driver IC, PoE module. Validate temps in enclosure with no airflow; adjust spacing/copper/heatsinking/duty-cycle assumptions.

  15. Current measurement accuracy plan (cal + noise)
    ESP32 ADC nonlinearity + Hall sensor offset/noise requires a calibration approach per channel (offset at 0A, scale at known load) and filtering (RC and/or ESPHome filters).

  16. Contact protection expectations need stronger enforcement
    You rely on external flyback diodes/snubbing. Ensure documentation is explicit (and consider optional footprints/test points) because inductive loads without suppression will shorten relay life fast.

@askpatrickw
Copy link
Author

askpatrickw commented Jan 1, 2026

Below are the 16 issues, each with a clear answer and datasheet / official-doc evidence.

  1. Relay part is latching, not a simple “ON while energized” relay

Proof: The Omron datasheet describes set/reset pulse width requirements and explicitly discusses latching relay operation.
Newyang

Answer: If you designed this like a normal relay (coil held on while load is on), it’s the wrong part/drive model.
Engineer action: Either:

Switch to a non‑latching G5RL variant, or Keep latching and implement pulse control + proper set/reset drive (see #2/#11).

  1. Single‑coil latching relay needs polarity control (can’t be “ULN sinks one side” only)

Proof: Omron notes to “check carefully the coil polarity” and provides separate set/reset behavior and pulse timing.

Answer: With a single‑coil latching relay, you typically need reverse polarity to reset. A ULN2803A low‑side sink alone cannot reverse coil polarity.
Engineer action: Use a coil H‑bridge (or equivalent polarity-reversal driver) per relay, or change to a two‑coil latching variant (set/reset coils), or change to non‑latching.

  1. ULN2803A voltage drop likely makes a 3V coil marginal from a 3.3V rail

Proof: ULN2803A VCE(sat) at 200 mA is up to 1.3 V. STMicroelectronics

Relay coil is 3 V, 200 mA, 15 Ω, and the “must operate voltage” is 70% max of rated. Newyang

Answer (with numbers):
Worst case coil voltage ≈ 3.3 − 1.3 = 2.0 V
Must-operate threshold max = 0.70 × 3.0 = 2.1 V
So worst-case is below spec → risk of non‑actuation across tolerance/temp.

Engineer action: Replace ULN2803A with logic‑level MOSFETs (very low Rds(on)), or a relay driver with low drop. If staying latching, pick an H‑bridge approach.

  1. ULN2803A thermal is unacceptable if coils are ever held on (fault case)

Proof: RθJA ≈ 55 °C/W.
STMicroelectronics

At 200 mA/channel, VCE(sat) ≈ 1.1–1.3 V.
STMicroelectronics

Answer (worst case): 8 relays × (0.2 A × 1.3 V) ≈ 2.08 W in the ULN → ~114 °C rise (2.08×55) above ambient. That’s a “will cook itself” failure mode.
STMicroelectronics

Engineer action: MOSFET drivers + firmware safety limiters, or distribute load across multiple packages, and design so a stuck output can’t hold a coil on indefinitely.

  1. PoE module output power is tight for 8 relays + ESP32 + sensors

Proof: AG9903MTB is 3.3 V, 6 W (70°C) / 4.5 W (85°C).
Silvertel

Max continuous output current for AG9903M/MT/MTB is 1.8 A.
Silvertel

ESP32 Wi‑Fi TX can be 160–260 mA depending on RF mode.
SparkFun

Relay coil is 200 mA each.
Newyang

Answer: If coils were ever simultaneously energized continuously: 8×200 mA = 1.6 A, leaving only 0.2 A margin for ESP32 + anything else; Wi‑Fi peaks alone can exceed that margin.

Engineer action: Ensure you never have “8 coils on continuously.” If you truly need non‑latching behavior, pick a higher‑power PoE solution (or different relay/coil rail).

  1. PoE module has minimum load + MPS behavior risk at low draw

Proof: Silvertel warns that operating below minimum ILOAD can create audible noise and may cause the PSE to fail its Maintain Power Signature (MPS).

Answer: If your board spends time in low-power idle (ESP32 modem sleep, relays idle), you can drop below what the PD module expects → PoE power may drop.
Engineer action: Confirm minimum-load requirements in the exact AG9903 datasheet section and design for it (bleeder resistor or periodic load), especially if aiming for low idle consumption.

  1. PoE front-end needs the exact bridge/cap network and placement

Proof: Silvertel’s typical connection shows bridge rectifiers from VA/VB pairs and calls out C1=100 µF (input) and C2=10 µF (output) in the reference diagram.
Silvertel

Answer: If you omit/misplace these, you’ll get start-up instability, ripple issues, or PoE negotiation problems.
Engineer action: Implement Silvertel reference exactly (bridges + caps) with tight placement to the module pins.

  1. PoE output capacitors: value/type constraints matter (stability + ripple)

Proof: Silvertel specifies capacitor requirements including C1 ≥ 100 µF and output capacitor guidance (MLCC/electrolytic options, ripple current considerations).

Answer: Random bulk capacitance selection is a common cause of brownouts when relays switch or Wi‑Fi transmits.
Engineer action: Follow the capacitor requirements and include local bulk near ESP32 as well (see #10).

  1. ACS712 cannot run on 3.3V (it’s a 5V part)

Proof: ACS712 supply voltage is 4.5–5.5 V; supply current is ~10 mA typ.
College of Engineering

Answer: With AG9903 providing 3.3V, ACS712s require an additional 5V rail (or a different current-sense IC).
Engineer action: Either add a 5V rail (and re-check PoE budget), or change current sensors to a 3.3V-compatible device.

  1. ACS712 output range can exceed ESP32 ADC safe range depending on variant

Proof: Zero-current output is VCC × 0.5 (so 2.5 V at 5 V).

Sensitivity examples from the datasheet:

~100 mV/A variant: 96–104 mV/A
College of Engineering

~66 mV/A variant: 63–69 mV/A
College of Engineering

Answer (10A case at 5V supply):

100 mV/A → 10A shifts +1.0 V → ~3.5 V output (over 3.3 V rail domain)

66 mV/A → +0.66 V → ~3.16 V (fits under 3.3 V, with little margin)

Engineer action: Lock the ACS712 variant selection deliberately and/or add scaling/clamping before ESP32 ADC.

  1. ESP32 ADC2 is not reliable with Wi‑Fi (ESPHome uses Wi‑Fi)

Proof: ESP-IDF docs: ADC2 is used by Wi‑Fi; ADC2 reads may be blocked/fail while Wi‑Fi is running.

Answer: Don’t design your 8 analog channels assuming ADC2 will be usable in ESPHome.
Engineer action: Use ADC1 pins only (or external ADC/mux) for current channels.

  1. ESP32 ADC attenuation: don’t assume you can safely measure “up to 3.9V”

Proof: ESP-IDF docs: 11 dB attenuation gives ~3.9 V full-scale, but also notes the maximum voltage is limited by VDD_A.
Espressif Systems

Answer: Designing to measure signals >3.3V into ESP32 ADC is not a robust plan; you still need proper scaling/protection.
Engineer action: Keep ADC input within ESP32 analog supply limits; use dividers/RC and/or buffering.

  1. Boot/strapping pins can be accidentally driven by relay circuitry

Proof: ESP32 strapping pins include GPIO0, GPIO2, GPIO5, GPIO12 (MTDI), GPIO15 (MTDO) and have required boot-level constraints; ESP32-WROOM datasheet explicitly warns about IO12/flash voltage selection.
Mouser Electronics

Answer: If your relay driver inputs, pullups, ADC networks, etc. touch these pins incorrectly, the board can fail to boot or enter wrong boot mode.
Engineer action: Constrain pinout to avoid strap pins for anything that could change at reset, and enforce correct default levels.

  1. ESP32 supply decoupling: you need local bulk, not just the PoE module caps

Proof: ESP32-WROOM datasheet notes a capacitor should be connected to VDD33.
Mouser Electronics

Answer: Relay actuation + Wi‑Fi bursts are classic brownout triggers without strong local decoupling.
Engineer action: Add bulk + HF decoupling near ESP32 module power pins (and verify brownout margin under worst-case switching).

  1. Omron “-E” high-capacity contacts require using both terminals

Proof: Omron explicitly states high-capacity “-E” models connect two terminals for one contact and you should use both; using only one may not meet performance.
Newyang

Answer: Your PCB and external wiring must tie/route both pins per pole correctly, or you risk contact heating / derating.
Engineer action: Ensure the PCB nets and connector mapping use both terminals as Omron instructs.

  1. “2mm traces for 10A” is not a safe blanket rule (needs IPC-based sizing)

Proof: Digi-Key provides an IPC-2221-based trace width calculator/resource.
DigiKey

Answer (IPC-2221-style math, 1 oz external copper): 10A continuous typically wants multiple mm of width for reasonable temp rise; 2mm is generally only acceptable with very high allowed ΔT, short runs, planes, or heavier copper.
Engineer action: Define copper weight (1 oz vs 2 oz), allowed ΔT, and length; then size pours/planes/vias accordingly and validate with an IPC calculator + thermal check.

Extra: Relay contact protection for inductive loads (your “external diodes” note is directionally right)

Proof: General relay contact suppression guidance exists (Omron surge suppressor circuits; DigiKey contact protection), and flyback diodes are standard for DC inductive loads.

Engineer action: Document required external suppression per load type (diode for DC coils, RC snubber/TVS where appropriate), and consider adding optional footprints if you want the board to be more foolproof.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment