PWM Control 24V Circuit with 3.3V ESP8266 NodeMCU
Something like this might work...



simulate this circuit &ndash; Schematic created using CircuitLab
The transistor selection is based on a max collector current of 100 mA or so.  There are many other possibilities.  The R1-R3 values were chosen to give ~20 mA of LED current.  Choose R4 so that you get the required amount of base current out of your MCU.