I am doing a circuit to drive a 5V 70Ohms relay using ESP8266. The max GPIO source current of ESP8266 is 12mA. I got this information from the forum here https://bbs.espressif.com/viewtopic.php?t=139#p600

According to my calculation, the required current to turn on the transistor will be around 7-8 mA. Can someone please cross check this and let me know if my calculation is wrong or correct and I doing it the correct way?

enter image description here

Initially I thought I'd be using an N Channel Mosfet, but I could not do that as I could not fit the LED easily like this. LED is important. I am open for any suggestion using Mosfet.

  • 2
    \$\begingroup\$ This is a highly unconventional "solution". There is no reason to put the LED in series with BE of Q1. One mistake however, you need to put the R2 between BE of Q1, not at the Logic GPIO side. You might have parasitic CB leakage, so the transistor will never turn OFF. \$\endgroup\$ – Ale..chenski Apr 13 '18 at 23:45

This approach for adding the LED to your SS8050 BJT is probably the simplest approach.


simulate this circuit – Schematic created using CircuitLab

I'm assuming \$20\:\text{mA}\$ for the LED requirements and \$\frac{5\:\text{V}}{70\:\Omega}\approx 72\:\text{mA}\$ for the relay coil. Together, I rounded this up to \$I_\text{C}=100\:\text{mA}\$ as the required collector current for your SS8050 BJT. (Nice choice of a BJT, if Fairchild's -- it's \$R_{\theta JA}=125\:\frac{^\circ\text{C}}{\text{W}}\$, which is unusually good for a TO-92 packaged device.)

Assuming the LED is a red LED and requires \$2\:\text{V}\$ at \$20\:\text{mA}\$ and leaving out \$V_{\text{CE}_\text{SAT}}\le 100\:\text{mV}\$ (which this BJT should easily achieve), I find \$R_2=\frac{5\:\text{V}-2\:\text{V}-100\:\text{mV}}{20\:\text{mA}}=145\:\Omega\$. I chose the nearest standard value there.

Given \$I_\text{C}=100\:\text{mA}\$, I find the datasheet suggesting \$V_{\text{BE}_\text{SAT}}\approx 800\:\text{mV}\$ with a saturating \$\beta=10\$. The datasheet for the ESP8266 suggests an output of about \$2.64\:\text{V}\$ worst case, when HI and supplying the full \$12\:\text{mA}\$ (which is close to your need.) So I find \$R_1=\frac{2.64\:\text{V}-800\:\text{mV}}{\frac{100\:\text{mA}}{\beta=10}}=184\:\Omega\$. I chose the nearest standard value.

If you wish (or, if you want to test out this circuit on a protoboard without the ESP8266 driving it directly), you can add a \$5.6\:\text{k}\Omega\$ resistor to ground from the base of \$Q_1\$.

Since I've provided the equations used to compute resistor values, you can plug in your own variations. So if you want to use a lower current for the LED, or if you have a different color LED that requires a different voltage to operate, you can easily recompute the values and use those new values, instead.


There is no reason to combine LED and Q1 control in one net. With your overly inventive schema you only push the functionality into a corner, since the LED might have a bigger forward voltage, and the transistor might need extra push to provide a necessary current for the relay, and GPIO might deliver only 2.7-2.8 V under load. Also you have no independent control of LED brightness, 5-6mA might be too much for modern LEDs as logic indicators, too bright.

Just put a series resistor from GPIO to the base of your transistor Q1, and put your LED in parallel to that GPIO, with another limiting resistor.


You have to watch out for the voltages. You have a voltage drop Ube about 0.7V, depending on the diode a voltage drop from about 1.6V to 3.5V! With Uq = 3.3V, and Ud 1.6V (Red LED) you can caluclate

UR = Uq-Ud-UBe = 3.3-1.6-0.7 = 1V

I=UR/R = 1/100 = 0.01A

So current shouldn't be the problem. Try another LED.

enter image description here

  • \$\begingroup\$ The datasheet of the transistor says Vbe Sat = 1.2V.. I am little confused with that.. Generally transistors have Vbe = 0.7 but for this one, datasheet says something else.. \$\endgroup\$ – Rakesh Mehta Apr 13 '18 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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