# Designing a transistor switching circuit with opto-isolation

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.

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?

• 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 Nov 16, 2020 at 4:37
• @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. Nov 16, 2020 at 5:07
• ESP32 IO pin gives 3.3V, LED drop in optocoupler is 1.2V, so 10KΩ gives 0.2mA through the LED; is that enough? Nov 16, 2020 at 17:53