I am working on a project where I want to switch a 12V DC LED strip(power consumption 300mA) using ESP32 having a complete isolation between LED strip power source. I came up with following circuit.

enter image description here

Here optocoupler is PC817, transistor is NPN 2n2222, LED-STRIP_ESP_14 is the esp32 GPIO pin, GND2 is esp32's GND, GND1 is common for 5V1 and 12V+, I'm using 5V at the phototransistor side of the pc817 because I have 5V readly available on another part of same circuit.

So, when LED-STRIP_ESP_14 goes HIGH, I want LED_STRIP to glow mode and when LED-STRIP_ESP_14 goes LOW, I want LED_STRIP to off.

Is this circuit designed correctly for the purpose?

  • 2
    \$\begingroup\$ No that relies on too much current gain to run saturated and cool. The pn2222 can be as low as 5 ohms with a 50 ohm driver but must have Ic/Ib=10 to 20 max. But if your Ic exceeds 50% of rated power it will be finger burning hot (85’C). So use a power FET \$\endgroup\$ Nov 16, 2020 at 4:37
  • 1
    \$\begingroup\$ @McLosys Creative, Welcome and nice to meet you. Ah let me see. (1) If I remember correctly, 2N2222 max current is 500mA. Now if your 12VDC LED strip is only 300mA, then of course 2N2222 can handle the job. (2) I remember 2N2222 current gain is around 100. (3) So let me do my dodgy calculation. Ib = Ic/gain = 300mA/100 = 3mA, (4) Now let me see if your Rb = 390R is OK: Rb = (Vcc - Vce(sat)1 - Vce(sat)2) / Ic = (5V - 1V - 1V) / 300mA = 3V / 300mA = (3000/300) = 10R. Ah it is locking down lunch time! I need to go and eat and let you verify my always dodgy calculation, (5) Rb = 10R OK?. Cheers. \$\endgroup\$
    – tlfong01
    Nov 16, 2020 at 5:07
  • 2
    \$\begingroup\$ ESP32 IO pin gives 3.3V, LED drop in optocoupler is 1.2V, so 10KΩ gives 0.2mA through the LED; is that enough? \$\endgroup\$
    – ocrdu
    Nov 16, 2020 at 17:53

1 Answer 1


The PC817 has a CTR of 50% minimum at 5mA, it's about half that at 0.2mA so you can only count on about 50uA going to the base. You should also derate for aging and temperature, which makes it even worse, but let's ignore that for now.

That will support the transistor switching about 1mA with it well saturated (Ic/Ib = 20), which is about 1/300 of your desired load current.

I suggest boosting up the LED current to at least 5mA, and using a MOSFET rather than a wimpy little signal BJT. You can use the +12V supply (the PC817 is rated at 35V) so it does not have to be a logic-level MOSFET.

  • \$\begingroup\$ this MOSFET sunrom.com/get/280424 will be suitable right? Also, I can boost the LED current by reducing resistance value, right? \$\endgroup\$ Dec 10, 2020 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.