2
\$\begingroup\$

I would like to use a STM32F microcontroller with 3.3V digital io pins which can deliver a max of 22mA to switch a transistor to then power a 5V relay which pulls 28mA. I'm not entirely sure what aspects I need to consider when selecting a transistor.

I've actually got 8 relays I wanted to power so I've found an a couple of quad npn transistor ICs which I think should do the job and I'm going to use 2 of them. FFB2222A and MMPQ3904

The collector currents are 500mA and 200mA respectively which should be ample (pun not intended). (These are ratings per transistor in the IC if I'm not mistaken).

What are the other things which need to be taken into account when selecting a transistor? Again if I'm not mistaken the transistor will be in the active region rather than saturated so we need to take in to account hfe, which should be sufficiently high for both. Is there anything else that needs considering?

Two other shorter questions with regard to the design.

1) When choosing a current limited resistor at the base does one assume the drop betweeen the emitter and the base is approximately 0.7? So 3.3-0.7=2.6V so assuming we want roughly 15mA going into the base 2.6V/15mA=173ohms (ish).

2) Also what things do you need to consider when choosing a flyback diode?

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
5
  • \$\begingroup\$ For switching, unless it needs to be fast (driving a relay, you probably don't), you probably want the transistor saturated. \$\endgroup\$
    – Colin
    Apr 19, 2018 at 11:32
  • \$\begingroup\$ But for the transistor to be saturated the base voltage has to be greater than the emitter and collector voltages? How do you achieve this? How do you calculate what the base and collector voltages will be considering the fact both the relay and resistor will drop some voltage. \$\endgroup\$ Apr 19, 2018 at 11:41
  • \$\begingroup\$ The solution is done by known the load Resistance and source resistance of each output with Vsat voltage What is your load R? 5V/28mA? \$\endgroup\$ Apr 19, 2018 at 12:02
  • \$\begingroup\$ You should be able to get an 8 Relay board cheap that you can drive directly from STN32F tvc-mall.com/details/… , maybe with current limiting R for optoisolation its not worth DIY \$\endgroup\$ Apr 19, 2018 at 12:18
  • \$\begingroup\$ Yes the coil resistance is 178 Ohms from the datasheet. I think I understand how to calculate the voltage, assuming that you are in saturation. But why can you assume that you will be? I've already picked the relays I wanted to use, and as well this board, I'm going to have another board relays with a spec for a higher current (20A) so it would still be helpful to know how to chose components appropriately. \$\endgroup\$ Apr 19, 2018 at 13:35

2 Answers 2

2
\$\begingroup\$

This is a classic saturated switching application. Your schematic is correct. In a saturated BJT switch there is a rule of thumb that the base current should be chosen to be around 1/10 of the collector current. This is sometimes referred to as using a forced beta of 10.

A forced beta of 10 is high enough to make sure that a typical BJT will be in saturation, and Vce will be low. Either of the suggested transistors will work. If memory serves, the 2222 is a bit better in saturated switching applications.

Since you know the collector current will be around 28 mA, you can pick R1 so that the base current will be around 2.8mA. Your formula for calculating the base resistor is correct. Just plug in 2.8mA instead of 15mA.

If you use one IO pin to supply multiple BJT's, make sure the total current is well under the limit. I would suggest that you use no more than 3 or 4 BJT's per IO pin in order to make sure the IO is not stressed. If you read the fine print, I am sure the IO pin cannot supply 22mA and stay close to VCC. Probably it is 22mA with Vout >= 2.4V or something like that.

If you use N-channel MOSFET's instead of BJT's, you can put all 8 on one IO pin. The BSS138 might be a good choice if you go that route.

\$\endgroup\$
3
\$\begingroup\$

You probably don't want to run in the active region, because the transistor voltage will mean that the relay sees less than 5 volts, so you will have to get the transistor saturated. Using the MMPQ3904 as an example, it lists VCE(sat) as 0.2 volts for IC = 10 mA and IB = 1mA, and 0.3 volts for IC = 50 mA and IB = 5mA. To get the transistor saturate with an IC of 28 mA, you can extrapolate to about 2.8 mA per relay switch, and realize that your transistor will have a VCE of around .25 volts, leaving 4.75 for your relay. Your transistor base voltage will be around 0.7 volts. Look at your IC output spec, and design such that the IC's output resistance and voltage can provide 3 mA to a load of R2 in series with a diode drop. Be sure your relay will work with 4.75 volts, and that your processor can deliver a total of 24 mA to the 8 transistor bases. Otherwise, find an N-channel enhancement MOSFET with a low on resistance and appropriate VGS(th). This will provide the same functionality with negligible processor current and voltage drop on the relay.

\$\endgroup\$

Your Answer

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

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