ESP32 LED PCB Design


A robust beginner-friendly onboard topology for each 24 V high-side channel is:
ESP32 GPIO → optocoupler or NPN level shifter → P-channel MOSFET high-side switch → LED color wire receives +24 V when active
This is simple, through-hole friendly, active-high from GPIO, and much more robust than trying to drive 24 V directly from the NodeMCU or using small signal transistors as the load switch.

First: challenge the assumptions
Before committing, verify these points:
  1. Do the LED “color wires” really need +24 V?
    Many 12/24 V RGB LED strips are common-anode: the common wire is +24 V and the R/G/B wires are switched to ground with low-side N-MOSFETs.
    If that is your LED type, you do not want high-side switching. You want three low-side N-MOSFETs.
  2. If the load wires truly need +24 V when active, then high-side switching is correct.
    That implies the LED/load common return is tied to 0 V/GND.
  3. Do not power the NodeMCU directly from 24 V.
    Use a 24 V-to-5 V buck converter feeding the NodeMCU 5 V/VIN pin, or a proper 3.3 V regulator. Most NodeMCU boards cannot tolerate 24 V on VIN.
  4. The external MT-301R4P-N module must be verified.
    Make sure it actually provides a 24 V sourcing/high-side output. Some opto modules provide sinking/open-collector outputs instead.
  5. If isolation matters, do not accidentally defeat it.
    If the external opto module is meant to isolate the ESP32 from the 24 V side, tying ESP32 GND to 24 V return elsewhere removes that isolation.

Recommended onboard channel circuit
Use this per channel for GPIO25, GPIO26, GPIO27.
Functional block

Text


ESP32 GPIO
   |
   |  logic input resistor
   v
Optocoupler or NPN pull-down stage
   |
   v
P-channel MOSFET gate drive
   |
   v
P-channel MOSFET high-side switch
   |
   v
LED color output receives +24 V when active

Preferred onboard robust version: optocoupled P-MOSFET high-side switch
This keeps the ESP32 side better protected and matches the spirit of the external opto-module fallback.
Per-channel schematic concept

Text


ESP32 side:

GPIO25/26/27 ---- RIN ---->| optocoupler LED ---- ESP32 GND
                    390R to 680R


24 V power side:

Protected +24 V rail
        |
        |
       Source
      QP1 P-channel MOSFET
       Drain -------------------- LED_COLOR_OUT
        |
       load to 0 V/GND externally


P-MOSFET gate network:

+24 V ---- RGS ---- Gate
          47k

Gate ---- DZ ---- +24 V
       12 V zener
       anode at gate,
       cathode at +24 V/source

Gate ---- RG ---- optocoupler transistor collector
       4.7k

optocoupler transistor emitter ---- 24 V return/GND
When the ESP32 GPIO goes high, the optocoupler turns on, pulls the P-MOSFET gate down, the P-MOSFET turns on, and the LED color wire receives +24 V.

Exact suggested values per channel

Table


ItemSuggested value / partNotes
High-side MOSFETFQP27P06, IRF4905, or similar P-channel TO-220 MOSFETUse ≥55/60 V VDS rating. Size current rating to LED load.
Gate pull-up resistor, RGS47 kΩ, 0.25 WKeeps MOSFET off by default.
Gate pull-down series resistor, RG4.7 kΩ, 0.25 WLimits zener/opto current.
Gate-source zener, DZ12 V zener, e.g. BZX55C12 or 1N5242BProtects MOSFET VGS from exceeding max rating.
OptocouplerDIP phototransistor optocoupler, preferably VCEO ≥ 50 VTLP785, VO617A, or similar. Avoid marginal parts if 24 V bus is noisy.
GPIO input resistor, RIN390 Ω to 680 ΩGives roughly 3–5 mA opto LED current from 3.3 V GPIO.
Optional GPIO pulldown100 kΩ from GPIO side input to GNDEnsures off during reset/boot if desired.
Optional output indicatorLED + 10 kΩ, 0.25 W from output to GNDShows channel active.
Optional output bleed100 kΩ from output to GNDPrevents floating output when off.

Why the 12 V zener is important
A P-channel MOSFET source sits at +24 V. If you simply pull its gate to 0 V, then:

Text


VGS = 0 V - 24 V = -24 V
Many MOSFETs have an absolute maximum VGS of only ±20 V. That is not safe.
The 12 V zener clamps the gate so that when on:

Text


VGS ≈ -12 V
That fully enhances most power P-MOSFETs while protecting the gate oxide.

Simpler non-isolated onboard version
If you do not need isolation and the ESP32 ground is already tied to the 24 V return, replace the optocoupler output transistor with a through-hole NPN transistor.
Per-channel non-isolated version

Text


ESP32 GPIO ---- 4.7k ---- base of 2N5551 / PN2222
                         |
                       100k
                         |
                        GND

NPN emitter ---- GND

NPN collector ---- 4.7k ---- P-MOSFET gate

P-MOSFET source ---- protected +24 V
P-MOSFET drain  ---- LED_COLOR_OUT

47k from P-MOSFET gate to source/+24 V

12 V zener from gate to source:
    zener cathode to +24 V/source
    zener anode to gate
Recommended NPN: 2N5551 is nice because it has higher voltage margin than a basic 2N3904. PN2222/2N2222 can work, but their 40 V rating gives less transient margin.

Example channel behavior
Assuming the optocoupled or NPN version:

Table


GPIO stateGate stateP-MOSFETOutput
GPIO low / resetGate pulled to +24 VOffFloating/off
GPIO highGate pulled about 12 V below sourceOnLED color wire gets +24 V
So the channel is active-high, which is intuitive for ESP32 firmware.

Power/input safeguards for the whole board
For a beginner-friendly 24 V board, I would add these before the three high-side channels:
1. Input fuse or resettable PTC
Place near the 24 V input connector.
Example:

Text


24 V_IN ---- fuse/PTC ---- protected +24 V rail
Select based on total LED current.
Examples:
  • 500 mA if the load is small indicators.
  • 1 A to 2 A for moderate LED loads.
  • Higher only if traces, connectors, MOSFETs, and supply are sized accordingly.
2. Reverse-polarity protection
Use either:
  • A series Schottky diode, simple but wastes power, or
  • A P-channel MOSFET reverse-polarity protector, better for higher current.
For a beginner board, a series diode may be acceptable at low current. For LED strips, use MOSFET reverse protection.
3. 24 V transient suppressor
Add a TVS diode across the protected 24 V rail:

Text


protected +24 V ---- TVS ---- GND
Suggested:
  • SMBJ33A or SMBJ36A, depending on expected supply tolerance.
Use a unidirectional TVS for DC supply protection.
4. Bulk capacitance
Near the MOSFETs and output connectors:
  • 100 µF to 470 µF, 35 V or 50 V electrolytic
  • 100 nF ceramic in parallel
Use 50 V caps if the 24 V supply is industrial/noisy.

Output safeguards per channel
For each LED color output:
  1. Per-channel fuse/PTC if wiring leaves the board
    Especially useful for beginner wiring mistakes.
  2. Optional output TVS or clamp for long cables
    If LED wires are long, add ESD/transient protection from output to GND.
  3. Flyback diode only if the load may be inductive
    For LEDs it is not required.
    If someone may connect a relay/solenoid, add a diode from GND to output:

Text


diode anode  ---- GND
diode cathode ---- switched output
  1. Use adequately rated screw terminals
    Do not use tiny headers for amp-level 24 V LED currents.

Jumper fallback arrangement
Do not let the onboard driver and external module fight each other. Use a selector jumper per channel.
Output selection jumper
For each color channel, use a 3-pin jumper:

Text


          [ONBOARD_OUT]
                |
                o
                |
LED_COLOR_OUT --o  center pin
                |
                o
                |
          [EXT_MODULE_OUT]
Jumper position chooses:
  • Center to ONBOARD_OUT: onboard P-MOSFET drives the LED wire.
  • Center to EXT_MODULE_OUT: external MT-301R4P-N module drives the LED wire.
This prevents both drivers from being connected to the same LED wire at once.

GPIO/input selection jumper
Also consider a second selector for each GPIO:

Text


GPIO25 ---- center jumper pin
              |
      -----------------
      |               |
 onboard input     external module input
This lets each GPIO drive either:
  • The onboard opto/NPN gate driver, or
  • The external module input.
If you do not add this, at least place series resistors so the GPIO cannot be back-driven by the external module.

Suggested connector/header layout
For the external MT-301R4P-N fallback, provide a header like:

Text


EXT MODULE HEADER

1  +24 V protected
2  24 V return/GND
3  GPIO25 signal, through 330R/1k
4  GPIO26 signal, through 330R/1k
5  GPIO27 signal, through 330R/1k
6  EXT_OUT_25
7  EXT_OUT_26
8  EXT_OUT_27
Then route EXT_OUT_25/26/27 to the output selection jumpers.
Label polarity and active level clearly on silkscreen.

MOSFET choice notes
For beginner through-hole use, TO-220 P-channel MOSFETs are convenient.
Good examples:
  • FQP27P06: 60 V, through-hole, good general choice.
  • IRF4905: 55 V, very low RDS(on), good for higher currents.
  • IRF9540N: common, but higher RDS(on); okay for smaller loads.
For 24 V systems, I would prefer 60 V or higher VDS. A 30 V MOSFET is too close to the bus voltage.

Recommended per-channel circuit summary
Use this as the onboard channel:

Text


GPIO25/26/27
    |
   390R-680R
    |
opto LED
    |
ESP32 GND


24 V side:

+24V_PROTECTED ---- source of P-MOSFET
P-MOSFET drain ---- ONBOARD_OUT_x

47k from gate to source
12 V zener from gate to source:
    cathode to source/+24 V
    anode to gate

4.7k from gate to optocoupler collector
opto emitter to 24 V return/GND
Then:

Text


ONBOARD_OUT_x ---- jumper option A
EXT_MODULE_OUT_x - jumper option B
LED_COLOR_x ------ jumper center

Final recommendation
For each of GPIO25, GPIO26, and GPIO27, use a P-channel MOSFET high-side switch with a 12 V gate-source zener clamp and an optocoupler or NPN pull-down gate driver. Make the onboard circuit active-high, off by default, and isolate it from the external module with proper selector jumpers.
If you want maximum beginner robustness, I would use:
  • FQP27P06 P-channel MOSFET per channel
  • TLP785 / VO617A-class DIP optocoupler per channel
  • 47 kΩ gate-source pull-up
  • 4.7 kΩ gate pull-down series resistor
  • 12 V zener from gate to source
  • 390 Ω to 680 Ω GPIO-to-opto LED resistor
  • Input fuse/PTC
  • SMBJ33A/SMBJ36A TVS
  • 100–470 µF bulk capacitor
  • 3-pin output selector jumper per channel
  • Optional GPIO/input selector jumper per channel
This gives you a safe, through-hole, understandable, field-tolerant high-side 24 V driver while preserving the external opto-module fallback path.
The initial schematic blocks are in: ESP32 socket, daisy-chain 24 V/I2C terminals, buck-module header, optional I2C pull-ups, external isolator fallback header, and onboard opto/MOSFET high-side driver channels.
I created the project spec and started the schematic for the jumper-fallback ESP32 24 V LED controller. The schematic now includes the ESP32 38-pin socket, 24 V/I2C in/out terminal blocks, buck-module header, optional I2C pull-up jumpers, external MT-301R4P-N fallback header, and three onboard opto + P-channel MOSFET high-side output channels; the latest check returned no open ERC warnings/errors.
Project file: Project Specification
Open items:
  • I’m blocked from making more edits right now because the account has no available ACUs.
  • I still need to update the spec with the final schematic details and cleanly mark my last verification todo complete.
  • We still need your LED current rating and eventual enclosure dimensions before PCB layout.
Optional I2C pull-up jumper explanation: I2C needs SDA/SCL pull-up resistors, but in a daisy chain you usually only want one set enabled. JP7 enables/disables the SDA pull-up and JP8 enables/disables the SCL pull-up; install the shunts on only one board/master location, and remove them on the other slave boards.
Update spec later
Set LED current
Add jumper notes
Check BOM cost

ESP32 24V LED Controller

ESP32 24V LED Controller thumbnail