Activate 12 V Relay with a 5 V GPIO

Ask QuestionAsked todayActive todayViewed 23 times1

What is the reason of using 10 kΩ resistor in series to the control signal? Is it related to the base current according to the NPN transistor’s datasheet?

For example:

  • My CONTROL/GPIO is 5 V.
  • The maximum base current according to the NPN transistor’s datasheet is 120 mA.

Does it mean I need to have minimum 42 Ω resistor?

enter image description here

relaybjtnpnShareCiteEditFollowFlagedited 1 hour agoSamGibson15.8k44 gold badges2828 silver badges5454 bronze badgesasked 1 hour agoRoy Roif1511 bronze badgeAdd a comment

3 Answers



Let us study the circuit design of a real High level trigger 5V relay KY019 shown below. The relay characteristics, operation, and photo are shown in Appendices A ~ C below.

The KY019 relay uses a Songle 5V relay switch, with nominal current of 90mA (measured 70mA). GPIO High is 3V3. For the OP’s 12V relay switch with smaller nominal current of 40mA, and GPIO High of 5V, it is easy to just modify the base resistor for a smaller collector current.

The NPN BJT SS8050 is used in this relay. The circuit analysis is shown in the right hand side of the schematic.

The calculation suggests a base resistance of 1kΩ. However for dirt cheap toy relays usually without any power saving requirements, the vendor usually takes a big safety margin to allow for the big variety of device parameters, a much strong base resistance 150Ω is used, to make very sure that the relays do switch, no mater how poor quality control are the transistors.

high trig relay


(1) How to properly use a relay module with JD-VCC from Arduino/Raspberry? – Asked 10 months Viewed 7k times

(2) Relay Module KY-019 5V – Rpi.org.forum 2018jun07

(3) SS8050 NPN Epitaxial Silicon Transistor – Faichild/On Semiconductor 2014nov


Appendix A – 5V/12V/24V Relay Datasheet Summary

relay characteristics

Appendix B – Relay switching I-V Summary

relay switching I-V summary

Appendix C – KY019 Relay Circuit Design Parameters


ShareCiteEditDeleteFlagedited 2 mins agoanswered 16 mins agotlfong011,93911 gold badge77 silver badges1313 bronze badgesAdd a comment2

The base current, if the GPIO input is actually at +5V, will be approximately (5-0.7V)/R.

You should pick the R to provide 1/10 to 1/20 of the DC current that the relay draws, according to the relay datasheet. That’s a rule-of-thumb with a typical jellybean NPN transistor. If you study the transistor datasheet you can usually find Vce(sat) values at Ic/Ib = 10.

For example, a 360mW 12V relay will draw approximately 30mA at room temperature. That means you should have 1.5 to 3mA of base current. So the resistor should be between about 1.5K and 3K.

If the GPIO does not give you quite 5V under that loading you might have to go a bit lower. In this case, assuming the GPIO gets within (say) 0.5V of Vdd, 2K could be a good value.

There is no need to supply excessive current to the base, it will result in needless power dissipation (much of it in the MCU at higher current levels) and the GPIO “5V” output will drop as a result of the excessive loading. Excessive current will negatively affect the reliability of the MCU chip.ShareCiteEditFollowFlagedited 50 mins agoSamGibson15.8k44 gold badges2828 silver badges5454 bronze badgesanswered 56 mins agoSpehro Pefhany289k1212 gold badges239239 silver badges603603 bronze badgesAdd a comment1

The current guaranteed to switch a relay is amplified by a saturated NPN here that only has about 10% of it’s maximum linear hFE and current drive capacity far greater than the load to support a low Rce/Rcoil ratip to dissipate the same ratio of load power e.g. a PN2222A has an Rce = Vce(sat)/Ic ~2 Ohms , so a 40 Ohm coil means the transistor uses 5% of the load power.

A PN2222A has a mean max hFE of 200 (100 to 300 @ 150mA) so the base current needs to be chosen using a ratio of Ic/Ib of roughly 20 thus Rb must be calculated from Vcc-Vbe/Iout * 20

e.g. if I coil is only 50mA then Ib can be 5% or 2.5mA thus Rb = (5-0.65V) /2.5mA=~1k8. It may switch with less current when the hFE is high unsaturated with 5k to 10k but then the Vce rises and thus the temperature. For low power relays of 12Vx50mA = 600mW your 10k can work if you must minimize drive current but if your relay coil is >1W then the transistor temp rise would be significant with 200’C/W thermal resistance.

Yet a 5V uC has a ~ 50 Ohm driver so a load of 100 Ohms is possible but not necessary here.ShareCiteEditFollowFlagedited 40 mins agoanswered 49 mins agoTony Stewart EE75109k33 gold badges4040 silver badges149149 bronze badgesAdd a comment

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.