Resistors between Arduino pin and transistor

I'm trying to activate a relay using an Arduino Uno. Most schematics I have seen in the web include two resistors between the Arduino pin and the 2N3904 transistor.

What is the reason for that?

• [as an aside] For flyback protection, use a Schottky diode. The back-EMF spike from the relay coil is fast. (See also comments here.) – Nick Alexeev Jun 12 '17 at 15:05
• @NickAlexeev. I have to call BS on the need for Schottky diodes for a forward conduction scenario such as this. A 1N4004 as shown has huge junction capacitance and this absorbs the initial energy. The 1N4004 would be just fine, and in this scenario you don't need fast reverse recovery or low forward voltage. – Jack Creasey Jun 12 '17 at 15:34
• My comments about a Schottky diode were related to driving an inductive load directly with a push-pull CMOS output. More about keeping Vf low so that undue current doesn't flow through the internal protection network than about speed. – Spehro Pefhany Jun 12 '17 at 16:35

The series base resistor (R9) is to limit the base current drawn from the Arduino output pin.

The resistor between base and GND (R10) is to conduct away the I/O pin's leakage current when it is tri-state. This will be the case after your circuit powers up (when reset configures then I/O pin as an input), until the Arduino CPU is out of reset and its software configures the I/O pin as an output. The leakage current may be enough for your transistor to conduct. The resistor value can be much higher than what you have, with 10 K to 47 K commonplace. Calculate it from R=Vilg/Ilk where Vilg is the input voltage from a good logic low (recommend 0.1 V) and Ilk is the I/O pin input leakage current (always see datasheet).

• The leakage current is unlikely to prove troublesome, but for many MCU's the digital/option pins are set as inputs during reset and may by default have a pullup resistor ....this can turn on a BGT or FET I/O buffer unexpectedly. – Jack Creasey Jun 12 '17 at 15:37
• Hi @JackCreasey, I've actually seen this problem on boards many times with this style of I/O pin into a BJT, between the input leakage current and the transistor's behaviour with a floating base. Arduino don't have a default pull-up (most modern don't seem to...only 8051 duplicates did?), hence stating Arduino in answer. – TonyM Jun 12 '17 at 16:01
• When you say "the resistor value can be much higher", are you referring to R9 or R10 or both? – Adrian McCarthy Jun 12 '17 at 17:46
• @AdrianMcCarthy, first paragraph only talks about R9, second only about R10. – TonyM Jun 12 '17 at 17:57
• R9

The resistor is here for current limitation. In your application, you want the transistor to switch on when the arduino pin is HIGH. To calculate that resistor value, you have to how much current will flow across the transistor when saturate ($I_c$). You can then determine the needed current coming from the arduino to toggle the transistor : $H_{fe}=\frac{I_c}{I_b}$ with $I_b$ the current delivered by the arduino. Knowing $I_b$, you can determine the resistor value.

• R10

This resistor is here to set a default value a the transistor's base, commonly called "Pull Down resistor". When the arduino is just power up, pin's voltage level is uncertain, that's why you need such a resistor.

• @TonyM I wasn't aware of it. I never use Arduino.. – M.Ferru Jun 12 '17 at 15:23
• Me neither. But finding the datasheet and checking took 2 mins :-) – TonyM Jun 12 '17 at 15:25
• @TonyM After few sec, I realize that on most µC, pull up or pull down are indeed programmable. There is no "default pin state" – M.Ferru Jun 12 '17 at 15:31
• @M.Ferru - it would be very rare for an MCU not to have a default state-upon-reset of the GPIO block. The ATmega328p datasheet will specify what it is. The Arduino bootloader which typically runs first could have been written to change that, but probably wasn't. – Chris Stratton Jun 12 '17 at 15:54

R9 is there to protect the logic driver. Consider the schematic below. Without a series resistor, when you drive the pin high, you are basically shorting the Vcc rail to ground through a diode. This will exceed the maximum current the pin can deliver and ultimately result in damage to the device.

The resistor needs to be large enough to perform that function while small enough to deliver sufficient base current to drive on the transistor hard enough to power the load. This is one of the reasons MOSFETs, which are voltage driven, and often preferred for this role.

simulate this circuit – Schematic created using CircuitLab

R10 is required to ensure the base of the transistor is held low while the micro initializes and has it's pin in a high impedance state.