# Selecting a switching transistor for a 5V relay

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?

simulate this circuit – Schematic created using CircuitLab

• For switching, unless it needs to be fast (driving a relay, you probably don't), you probably want the transistor saturated. Commented Apr 19, 2018 at 11:32
• 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. Commented Apr 19, 2018 at 11:41
• 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? Commented Apr 19, 2018 at 12:02
• 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 Commented Apr 19, 2018 at 12:18
• 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. Commented Apr 19, 2018 at 13:35