I am controlling relay from arduino, using the following circuit.
I want to understand what is use of R41 (base to emitter resistor)?
Is it required for base termination?
How is its value calculated?
I am controlling relay from arduino, using the following circuit.
I want to understand what is use of R41 (base to emitter resistor)?
Is it required for base termination?
How is its value calculated?
It prevents leakage through the optoisolator from partially turning on the transistor.
Find the maximum leakage of the opto (typically it will occur at the maximum junction temperature ever expected) and calculate the resistor to drop no more than something like 0.4V. Then go back and make sure that it's not hogging too much base current under worst-case (low) CTE etc.
That particular opto has 1uA typical leakage at Tj=100'C, so you might want to allow for 3-10uA worst-case.
I can't read the values there very well, but typically R3 and R41 about the same value works, and if that is actually 115K, it looks way too high to reliably drive a relay, especially considering the relatively poor guaranteed gain of the MMBT2222.
The collector-emitter dark current for the EL3H7 opto is given as 100 nA maximum and this won't be sufficient to activate the BJT and turn on the relay but you can never rule out leakage currents across the opto from the driven side having small effects so it's probably a good idea to have this resistor just to act as a weak pull-down.
So, as a weak pull-down a value from 10 kohm to 100 kohm won't hurt too much and might just save a bit of head-scratching should the relay trigger falsely if the resistor isn't there.
It improves the noise margin of Q1. There are some relay modules without this resistor and many complaints about random false triggering like here.
It's value is not critical, low enough to have a better noise margin but high enough to leave Q1 a good base current.
The base current can be approximated as the difference between current through R3 and current through R41 considering Q1 Vbe ~= 0.8V
Ir3 ~= Vcc/R3 = 24V/115kohm = 0.2 mA
To estimate the minimum base current required we use the coil/collector current which is less than 17mA for a G5LE relay and Q1 amplification factor that is 50 worst case for MMBT2222, so the minimum base current should be 17mA/50 = 0.34mA
Now we cam see that whoever designed this took a Q1 amplification of 17mA/0.2mA = 85 which is not safe.
Just for exemplification let's take a 150 minimum Q1 current amplification. That leads to a 17mA/150 = 0.11mA minimum Q1 base current. The difference of 0.089mA up to 0.2 mA can go through R41.
With a 0.8V Vbe the result is R41 >= 0.8V/0.089mA = 8.9kohm
Update to show an example with a maximum value of R41.
If there is a leakage current from opto output , Iopto, this will translate in a permanent current through Q1 which can damage Q1 or maintain the ON state of the relay that requires much less current than the nominal current.
Worst case Q1 I collector is Iopto * maximum amplification factor of Q1
For 100nA leaqkage current and max beta = 300 Ic will be 30uA
For this relay the "must release" current is specified at 10% , 1.7mA , much higher than the 30uA above.
The power disipated on Q1 due the leakage current is 30uA*24V = 0.72mW, also in Q1 parameters.
To make sure Q1 is closed we need a voltage less than 0.5V on the base. With a 100nA current that leads to 0.5V/100nA = 5Gohm maximum value.
Obviously here we won't go that high for R41, it was just a theoretical example.