Transistor connection from Microcontroller output

Discussion in 'General Electronics Chat' started by Lanz, Nov 18, 2009.

  1. Lanz

    Thread Starter Active Member

    Oct 30, 2008
    I use microcontroller to control a relay by using transistor.
    The connection was as diagram no1.Im not sure wether the circuit will work or not.I dont know wether to use NPN or PNP transistor and the differences on the circuit.So plz someone clarify the diagram with related theory and which diagram is correct.


    • npn.jpg
      File size:
      74 KB
    • pnp.jpg
      File size:
      72.8 KB
  2. Papabravo


    Feb 24, 2006
    You cannot do this the way they are drawn. To activate a PNP transistor you need a series resistor from the micro controller to the base to limit the base current. Next a pullup resistor from the base to VCC to turn the transistor off. Last you need to see what collector current will be pulled through the relay coil and a load resistor may be required if the impedance of the coil is too low. To use an NPN transistor you need the resistor from the micro controller to the base, and a pull down resistor to turn the transistor off. The additional load resistor depends on the coil impedance.

    Lastly you will need a diode in parallel with the coild to absorb the inductive kick when you turn the coil off.

    You must not have researched this topic very well to have missed all of those points.
    Check out the following hits from "Relay Coil Driver Circuit"
    Last edited: Nov 18, 2009
  3. SgtWookie


    Jul 17, 2007
    This is basically what Papabravo was talking about:


    Your figure 1 was the closest to being correct.

    The diode across the relay coil can be any 1N400n series diode (1N4002, 1N4004, etc)

    The absolute minimum value for the base resistor is 220 Ohms. This will cause about 20mA current to flow from the I/O pin when it is high, which is the maximum current for many microcontrollers. If you go below 220 Ohms with a Vcc of 5v, you will very likely damage, or at least shorten the life of the uC.

    Values of 470 Ohms to 1k Ohms are very frequently used with uC projects for transistor base current limiting resistors. To ensure good saturation of the transistor, you need a base current that is 1/10 of the expected collector current

    If your relays' coil requires 100mA current, then you need 10mA base current.
    A "quick and dirty" formula for calculating a base resistor is:
    Rbase = (Vcc - Vbe) / (Ic/10)
    Your Vcc is 5v.
    For this exercise, we'll assume that Vbe (voltage on the base relative to the emitter) will be 0.7v.
    Ic (collector current) is 100mA.
    Rbase = (5v - 0.7v) / (100mA/10) = 4.3 / 10mA = 4.3/0.01 = 430 Ohms.

    If your I/O pin that is being used to drive the transistor's base will always be used as an output, you will not need a pull-down resistor. If for some reason it will ever be used as an input pin, or otherwise set to high impedance, you should use a 4.7k resistor from the base to the emitter to ensure that it stays turned off.

    Note that energizing/de-energizing the relay will create large voltage transients (surges/spikes) on Vcc. You will need large and small capacitors to absorb those transients. 220uF and 0.1uF caps might be adequate.
    Always use 0.1uF capacitors across the supply/ground pins of integrated circuits.
    Last edited: Nov 18, 2009
  4. Papabravo


    Feb 24, 2006
    Thanks for the graphics and the deeper explantion Sarge. Always appreciated.