Electronic – Selecting a switching transistor for a 5V relay

diodesflybacknpnrelaytransistors

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

Best Answer

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.