Site hosted by Angelfire.com: Build your free website today!
« July 2009 »
S M T W T F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Entries by Topic
All topics  «
Blog Tools
Edit your Blog
Build a Blog
RSS Feed
View Profile
You are not logged in. Log in
My Blog
Tuesday, 19 May 2009
Driving a relay

Driving a relay from a microcontroller is quite easy.  A handful of inexpensive components are all you need.  Here is the schematic diagram

 

 

 

 

 

 

 

 

 

 

The NPN transistor is used as a "low side" driver.  Almost any small signal transistor will work in this circuit.  The control signal comes from a microcontroller or other digital logic.  R1 is used to limit the base current.  1KΩ is probably a bit low but will work ok.  More on that later.  R2 is used to keep the base at GND during power up where the microcontroller's output might fluctuate.  This prevents the transistor from turning on when you don't want it to.   I've selected 470KΩ but anything from 100K to 1M would be fine.  The diode D1 is used to supress back EMF.   When removing power from the coil, the collapsing magnetic field will generate a voltage spike which could damage the transiistor or other logic.  The inverted diode conducts this onto the voltage rail and protects the rest of the cuircuit.  I specified a 1N4004 but that's really overkill.  Even the lowly 1N4148 would suffice.  

We need to make some calculations to determine the correct value of R1.   We will start with the current draw of the relay.  I've selected a G5LE, a poplular line of relays from OMRON.  It comes in a number of different voltage and coil power ratings; I chose the 5V, 400 mW model.  It has a coil resistance of 63Ω and a current draw of 79.4mA at 5V.  So, we need to cause Q1 to draw at least 79.4 mA from the relay coil.  The 2N2222 transistor we are using has a minimum DC gain (Hfe) of 60.  That means the for every mA of base current (Ib) the 2N2222 will draw 60 mA of collector current (Ic). To deliver 79.4 mA, we will need and Ib of 1.3mA  (79.4/60 mA).  Use Ohms Law to determine R1.  V= Ib*R1.  Assuming the controller is running at 5V, we have 5 = .0013*R1.  Or R1 = 5/.0013 = 3486Ω.  Since you can't buy 3486Ω resistors, pick the next lower standard value. In this case 3.3KΩ.

The above calculations were based on ideal conditions.  The voltage from the controller is often somewhat below the supply voltage so we should factor that in.  I'll pick 4.5V as the likely minimum voltage.  So recomputing; R1 = V/Ib = 4.5/.0013 = 3462Ω.  That still leaves us with the standard value of 3.3KΩ. 

Another thing to consider is that there is some voltage drop through a bipolar transistor.  It is safe to assume .7V though at these current levels, the data sheet tells us that the drop will be lower.  However, since the actual current will be a bit lower than the datasheet shows, we don't need to worry about it.  The relay has a fairly wide operating range so we don't need to worry about the lower voltage.

Now, why did I show the value of R1 as 1K?  With a 1K base resistor and a 5V control signal, Ib would be 5 mA.  Well within  the limits of most microcontroller and digital logic chips.  With a gain of 60, collector current (Ic) would be 300 mA.  Way too much?  No.  The relay will limit the current to what it needs.  So, any resistor from 1KΩ to 3.3K will work.  It's not uncommon to see a base resistor of 2.7KΩ as that is good enough for most relays.

One other issue that you should be aware of when using relays with digital logic.  If you can help it, don't power the relay coil from the same voltage rail as your digital logic.  Energizing the relay coil causes noise and voltage fluctuations.  This can cause digital logic and microcontrollers to do unexpected things like reset.   If you must power both from the same source, use a large capacitor near the relay coil to supply some of the current the coil needs.


Posted by phil.ba at 3:16 PM EDT
Updated: Thursday, 28 May 2009 6:28 PM EDT
Post Comment | Permalink | Share This Post

Newer | Latest | Older