Connect with us

flip relay with 2n3904

Discussion in 'General Electronics Discussion' started by Bogo57, Mar 8, 2014.

Scroll to continue with content
  1. Bogo57

    Bogo57

    3
    0
    Mar 8, 2014
    I have a relay that I am controlling via micro controller, bringing extra power to the coil via 3904.

    The relay says "5v" on it, then the data sheet says 9v to activate the coil. I tried 5 and it worked, but I plan on sticking to 9v. The sad part is that my power supplies are 5v and 12v.

    With experimentation anything 5-12v will flip the relay. 9 is what the data sheet says. Is there any good reason to use more or less? The 3904 I have says it can do 40v or so, making me think I could use the 12v line as is thru my 3904. Or I could try withy the 5v line and hope it always works. I have a hunch it may be best to use a lm317 and drop my. 12v to 9v for the coil. Is that true, and why?

    Thanks mucj
     
  2. kpatz

    kpatz

    316
    84
    Feb 24, 2014
    What relay is it? So I can see the data sheet.

    Usually if a relay says "5V", it means the coil is rated for use at 5V. It can handle more, and should work with (at least slightly) less. But if you put too much voltage (and more specifically, current) through, it could heat up and burn out.
     
  3. BobK

    BobK

    7,682
    1,686
    Jan 5, 2010
    The datasheet says it is a 12V coil, so use 12V since it is available.

    Bob
     
  4. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    Oh dear. Chinese quality control strikes again.

    That data sheet has been copied from the data sheet for a relay with a 12V coil but most of the numbers, and the photo, haven't been changed. So it's inconsistent.

    On the first page, the part number includes "05VDC" which is pretty clear in its meaning - the coil is specified to operate at 5V DC.

    The specifications on page 2 are for a relay with a 12V coil. This explains the "Coil Rated Voltage" figure of 12V and the "Pick-up Voltage" of 9V (75% of nominal voltage).

    This pick-up voltage is just the coil voltage at which the relay is guaranteed to pull in; it's generally 75~80% of the rated voltage, but you should always apply the full rated voltage.

    The other specifications are not consistent for either a 5V or a 12V relay, unless the coil power dissipation is 450 mW (not the 200 mW claimed in the third bullet point on page 2), in which case they are also for the 12V coil version.

    Long story short: ignore the data sheet!

    If the relay you have in your hand says 5V, drive it from 5V. If you would rather drive it from 12V, for example to reduce the current drain on the 5V regulator, you can, but you need to put a resistor in series with it. In that case, measure the coil resistance and I'll show you how to calculate the value of the series resistor you need.

    Don't drive it from 9V or 12V without a series resistor. The coil will get hot. And if the quality of the relay is anything like the quality of the data sheet, it will probably fail!

    As always, you need a reverse-connected diode (typically from the 1N400x series) across the coil to protect the transistor from the back EMF that's generated by the relay coil when the transistor turns off.
     
  5. Bogo57

    Bogo57

    3
    0
    Mar 8, 2014
    That is exactly what I was looking for, thank you for that and so much more explanation!

    Is there anything wrong with driving this relay direct from an arduino, or (pointlessly?) via 2n3904 with the source being a plain 5v line from the arduino output?
     
  6. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    Yes, there is a lot wrong with driving a relay coil directly from an Arduino. It won't work. The Arduino's outputs are not able to supply very much current - you shouldn't try to draw more than about 10 mA from them - and the relay coil needs significant current.

    You can calculate the coil current from the coil voltage and the power consumption, using the Power law: P = V I. This rearranges to I = P / V where I is current in amps, P is power in watts, and V is voltage in volts.

    It's not clear whether these relays have a coil power consumption of 200 mW or 450 mW so I'll calculate for both.

    Assuming 200 mW coil power, I = P / V = 0.2 / 5 = 0.04 = 40 mA
    Assuming 450 mW coil power, I = P / V = 0.45 / 5 = 0.09 = 90 mA.

    That's the reason for the 2N3904. Say the resistor from the Arduino output to the base is 2k2 (2200 ohms). When the Arduino output is high, there will be about 4.4V across the resistor (about 5V at the Arduino end, and about 0.6V at the base - this is the "base-emitter forward voltage" of the transistor).

    Using Ohm's Law you can find the current that flows out of the Arduino pin, through the resistor, and into the base of the transistor. Ohm's Law says I = V / R where I is current in amps, V is voltage in volts, and R is resistance in ohms. Applying this to the series resistor we get I = V / R = 4.4 / 2200 = 0.002 = 2 mA.

    So only 2 mA flows from the Arduino to the transistor. The transistor has a current gain of about 100~200, so it will allow around 200~400 mA to flow through its collector-emitter path.

    The resistance of the relay coil will limit the current through it to 40 mA (or 90 mA if it's a 450 mW coil) so the transistor will saturate, pulling its collector nearly all the way down to 0V and providing nearly 5V across the coil.

    That's what you need to do.

    A modern alternative to a BJT (bipolar junction transistor) (the 2N3904) is an N-channel MOSFET such as an FDV303N (http://www.digikey.com/product-detail/en/FDV303N/FDV303NCT-ND). This is a SMT (surface mount technology) device, and it's also static-sensitive and needs proper handling. Its advantage over the 2N3904 is that it doesn't draw a continuous current from the Arduino pin, which is great for low-power applications, but this application obviously isn't one of those. To use a MOSFET, you connect the Arduino pin straight to the MOSFET's gate, with a high-value pulldown resistor from gate to source (100k or so). The pulldown resistor keeps the MOSFET turned OFF when the Arduino isn't driving it (e.g. during reset, when all its pins go floating). It draws a tiny amount of current. Just FYI.

    No matter how you drive the relay coil, you need a reverse-connected diode across it - that is, a diode with its anode to the transistor's collector and its cathode to +5V - to protect the transistor against the back EMF voltage spike generated by the relay coil when the transistor turns OFF. This voltage spike would pull the transistor's collector up to a high voltage and possibly damage it (as well as creating electrical interference). A diode from the 1N400x family is usually used.
     
  7. pilko

    pilko

    26
    10
    Dec 8, 2012
    @ KrisBlueNZ,
    The time and effort you devote to helping people on this forum is incredible. You do this unselfishly and for free.
    Just to let you know that your efforts do not go unnoticed.
     
  8. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    Thank you pilko :)

    I have plenty of time because I'm unemployed, and I enjoy it.
     
  9. Arouse1973

    Arouse1973 Adam

    5,164
    1,081
    Dec 18, 2013
    Yes I agree :)
     
  10. Arouse1973

    Arouse1973 Adam

    5,164
    1,081
    Dec 18, 2013
    Unemployed with your skills???
     
  11. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,270
    Nov 28, 2011
    Yeah, I'm afraid so. There's not much work here for design engineers and embedded systems programmers. But I'm always hopeful. Thanks for the comment :)
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-