4
\$\begingroup\$

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?

Relay circuit with resistors highlighted

\$\endgroup\$
  • 2
    \$\begingroup\$ [as an aside] For flyback protection, use a Schottky diode. The back-EMF spike from the relay coil is fast. (See also comments here.) \$\endgroup\$ – Nick Alexeev Jun 12 '17 at 15:05
  • 3
    \$\begingroup\$ @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. \$\endgroup\$ – Jack Creasey Jun 12 '17 at 15:34
  • \$\begingroup\$ 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. \$\endgroup\$ – Spehro Pefhany Jun 12 '17 at 16:35
3
\$\begingroup\$

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).

\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Jack Creasey Jun 12 '17 at 15:37
  • \$\begingroup\$ 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. \$\endgroup\$ – TonyM Jun 12 '17 at 16:01
  • \$\begingroup\$ When you say "the resistor value can be much higher", are you referring to R9 or R10 or both? \$\endgroup\$ – Adrian McCarthy Jun 12 '17 at 17:46
  • \$\begingroup\$ @AdrianMcCarthy, first paragraph only talks about R9, second only about R10. \$\endgroup\$ – TonyM Jun 12 '17 at 17:57
4
\$\begingroup\$
  • 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.

\$\endgroup\$
  • \$\begingroup\$ @TonyM I wasn't aware of it. I never use Arduino.. \$\endgroup\$ – M.Ferru Jun 12 '17 at 15:23
  • \$\begingroup\$ Me neither. But finding the datasheet and checking took 2 mins :-) \$\endgroup\$ – TonyM Jun 12 '17 at 15:25
  • 1
    \$\begingroup\$ @TonyM After few sec, I realize that on most µC, pull up or pull down are indeed programmable. There is no "default pin state" \$\endgroup\$ – M.Ferru Jun 12 '17 at 15:31
  • \$\begingroup\$ @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. \$\endgroup\$ – Chris Stratton Jun 12 '17 at 15:54
2
\$\begingroup\$

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.

schematic

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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