0

In addition to my last post I have more information and details.

I want to run 240V Relay (5V Coil) from my AVR chip (ATmega328P).

My EMR relay takes up to 200mA on it peak.

I have 2N2222 transistor, and I have MOSFET (IRFZ44N power MOSFET).

What is the criteria to deiced which transistor to use?

The BJT can allow up to 800mA (which is ok for me), and the IRFZ44N can take up to 50A (which looks too much), but I also find some MOSFETs that runs 1A.

It looks like the MOSFET is easier, just connect the output pin from the IC to the gate and that's it, while the BJT has some calculations involved. Am I right?

gabi
  • 343
  • 2
  • 5
  • 17

2 Answers2

2

schematic

simulate this circuit – Schematic created using CircuitLab

The IRFZ44N would likely work, but it may be slower in switching and definitely overkill for your project. The 2n2222 transistor should work fine. I would take 200mA divided by the minimum gain of the transistor (hfe=35) and you'd get the current that you need to send into the base of your transistor. 200mA/35=5.714mA into the base of the transistor. The Vbe (voltage between the base and emitter) when on is generally around 0.7V. So you have 5V-0.7V = 4.3V. Then you need that 4.3V to push 5.7mA of current. Using ohm's law you get 4.3/0.0057 = 754 ohms of resistance.

In summary, you'll have about 6mA of current flowing through the base to the emitter which with minimal gain of 35 you'll end up with 200mA of current from collector to emitter. Attach the collector to the 5V relay coil, the other side of the relay coil to Vdd, and you should be set.

horta
  • 12,738
  • 22
  • 45
  • What will happend if i use much smaller resistor? Lets say 100ohm, so with 4.3V I will throw 43mA from the iC (sure, it will blow) but the coil will draw UP TO 200mA, so with 35 Hfe, it will still draw only 5.7mA, no? – gabi Apr 09 '14 at 20:15
  • 1
    The coil has a certain built in resistance. It also has certain power limitations. Without a spec sheet on the relay, I assume 200mA is the **maxium** current that it can take. When you apply 43mA to the base of the transistor, you have the ability to allow 43mA*35 = 1.5 Amps through the relay. That will not only blow up your 2n2222, you'll very likely blow up your relay. The relay itself won't have any protection from overcurrent besides its inherent resistance so max of 5V/Rrelay=Rcurrent. If its internal resistance is low (and it should be) it will allow any amount of current through. – horta Apr 09 '14 at 20:28
  • I always hearring "the consumer will draw as much current as it needs", lets say I have 2V 2 Amps source, and my LED drops 2V, and need 20mA, it will not blow up, right? So why the coil will take more than it maximum needs (200mA)? Of caurse , if my part needs more than 1A it will blow the BJT, and blow my iC (1000/35=28mA on the iC pin) – gabi Apr 09 '14 at 20:39
  • 1
    No, if the LED is meant to have a turn-on voltage of around 0.7V (a typical red LED). If you drop 2V across it, it will likely consume all 2 amps your source gives. That is before it releases its magical smoke... That is why normal LEDs (non-power LEDs) always have a resistor in place to prevent over current through the LED. – horta Apr 09 '14 at 20:42
  • 1
    I think the quote you gave "consumer will draw as much current as it needs" applies to linear elements (resistors, caps and inductors). This follows through Ohm's law: V=I*R. An LED is non-linear device, and your relay will likely have a virtually 0 Ohm resistance. That means, if you have a 2V, 2A power supply to it, it will try and consume all the current you offer. 2V/0ohms = infinite. So the practical limit is the maximum 2A that your power supply offers. – horta Apr 09 '14 at 20:46
  • If i have 1V supplier, with 1A, do I need resustor to run regular LED? If so, how should I calculate thd value? – gabi Apr 09 '14 at 20:55
  • 1
    (1V - Diode-turn-on-voltage)/resistance = Current. So if the diode operates at 20mA and the diode turns on at ~0.7V then you have 0.3V/0.02A = 15 Ohms. And what do you mean by thd value? – horta Apr 09 '14 at 21:04
  • Sorry, I meant to ask for example that the LED needs 1V, so the formula will be 0V/0.02A=0ohm. In this example we will not use resistor, right? The operation V and supplier V is the same.. So the LED will "takes" thd current ig needs, right? – gabi Apr 09 '14 at 21:10
  • 1
    Yes, that's generally the case for power LEDs. Instead of burning power through a resistor, the power LEDs can handle a bit more slop in the amount of current they consume. Even then, it's still a bad idea to use a voltage source without a current limiting device on an LED because each LED is made slightly different. Review the graphs on this page: http://www.electronics-tutorials.ws/diode/diode_8.html and you'll see that a **very slight** change in voltage results in a very large change in current potentially frying the LED. – horta Apr 09 '14 at 21:19
  • You are very patient, thank you :-) . If my transistor Hfe will be 50 instead the 35 we just calculate, and the resistor will be 750ohm as we calculate, the coil will have 290 mA, which will damage it, on the datasheet it said maximum of 200mA.. The 2n2222 datasheet shows varies of Hfe value (depend on the current if I understood if right..). Am I right? – gabi Apr 09 '14 at 21:25
  • 1
    Yes, you would be right. Which means you should probably limit the current by adding a resistor in the path of the relay if it can't handle over a certain amount of current. If you do that, then you can lower your base resistor and rely less on the hfe of your transistor. – horta Apr 10 '14 at 00:40
  • Hi, Ok - I got the idea, but I am trying to calc the resistor in the coil line - it should be 5V/0.2A = 25ohm, am I right? putting 25ohm resistor on the coil line will "save" my coil from over current than 200mA on the 5V line? Also - is this related to the 10K resistor I can see on EP answer diagram down this page? Thanks. – gabi Apr 10 '14 at 05:57
  • 1
    Yes you are correct on your calculations. Adding 250 ohms to the coil line will prevent burnout. This is **not** related to the 10K resistor you see on EP's answer. That 10K actually comes from another question I answered recently: http://electronics.stackexchange.com/questions/105973/do-n-channel-mosfets-require-a-pull-down-resistor/105976#105976 The need for that resistor on a BJT isn't necessary, but it can improve switching times slightly. – horta Apr 10 '14 at 13:43
  • 1
    Also, before blindly adding 250 ohms, you should probably check the resistance of the coil. It's possible that there's already some resistance on it. If there is, you could subtract that coil resistance from 250 ohms and put that value in instead. Doing this has the potential to make your relay switching time faster/stronger. – horta Apr 10 '14 at 13:44
  • How did you got 250ohm? 5v/0.2A is 25ohm, no? – gabi Apr 10 '14 at 17:33
  • 1
    Typo I meant 25 ohms. Thx for keeping me honest. – horta Apr 10 '14 at 17:39
  • The coil resistance is 27ohm +-10% :-) So I should not put resistor in the line, right? Also in the datasheet it wrote the rated V is 5V, but the drop-out is 0.5V and pick-up is 3.75V. Is it relevant to the subject? What is those values? Thank you! – gabi Apr 11 '14 at 10:18
  • 1
    Right, you don't need a resistor in line for it to work. In fact from the other stuff you posted, putting a resistor in line would likely make it not work. Pick-up is voltage at which the coil will turn the switch on. Drop-out is the voltage that the coil will switch off as you drop the voltage. If you have ~25 ohm resistor in series with your coil, then you'd get 1/2 of your voltage or 2.5V across the relay, and it won't ever turn on because the pick-up is 3.75. You only need a resistor on the base side. – horta Apr 11 '14 at 14:38
  • So I dont have 750ohm resistor, and I used 1k ohm resistor instead. The datasheet said the coil is 27ohm on 5V, r=5/27=185mA. On Hfe=35 , 185/35=5.28mA from the iC output pin, the base drop voltage is 0.7V, so with 1k resistor it needs V=0.00528*1000ohm=5.28V+0.7V=6V. With Hfe of 150 : 185/150=1.23mA, V=1.23+0.7=2V. So if the gain is 35 I have problem.. If thd gain is 150 I am OK, right? Did I got the calculatuons right? – gabi Apr 11 '14 at 15:39
  • I am asking becase I am using 1k resistor, and after I am turning the relays the iC start to work REALLY slow… I am powering 2 relays from PORTC2 and PORTC3 pins. – gabi Apr 11 '14 at 15:42
  • 1
    This is starting to head into the debug arena. Could you send a link of the relay datasheet? Even if you use a 1k resistor, you'll have 4.3V/1k*35hfe*27ohms = 4.06V across the relay, which should reliably turn it on. It may be a bit weak though. I would put 2 1k's in parallel to get yourself 500 ohms. Since your relay has its own internal resistance, you won't blow anything out. When you have it turned on, check the voltage at the output pin of the uC and the voltage at the base of the transistor. If you could pull the voltages of your Vdd and after the relay while on, that'd be helpful too. – horta Apr 11 '14 at 16:02
  • BTW horta, this is the datasheet: http://webcache.googleusercontent.com/search?q=cache:http://www.bcrelays.com/Relay.JQX-15F.pdf I am using the 5V coil – gabi Apr 11 '14 at 21:31
  • Btw, what do you mean by iC starts to work really slow. What precisely takes a long time? – horta Apr 11 '14 at 21:36
  • The AtMega328p powering 2 relays, and it connected to LCD and nRF24L01. the signal got from the controller RF and powering the relays, the LCD update the string to "ON". when the relays is up, I cannot get any other signals on the RF.. replacing the relays with LEDs works fine.. the nRF connected to LM1117-3.3 voltage regulator because it needs 3.3V to work. weird stuff.. I will try to get all the voltages across the circuit and update here.. – gabi Apr 11 '14 at 22:07
  • I am adding secinds count and displaying it on the LCD now to see if the uC works fine after powering the relay up.. – gabi Apr 11 '14 at 22:40
  • Another thing, the piwer converter is cheap AC-usb 5V converter, should be up to 1A output.. – gabi Apr 11 '14 at 22:41
  • This is starting to sound like a power rail droop issue. When both relays are on what's your VDD at? It sounds like the relays are working fine, it's just that the rest of the circuit is now either momentarily seeing a drop/droop in power or you're constantly sucking lots of power. Both relays on would suck about half of your power (if it actually can support 1A). If you measure VDD when the relays are on and it's still near-ish to 5V, then it's likely transient. In that case, add a decent sized capacitor between gnd and Vdd: try 10-100uF. – horta Apr 12 '14 at 00:22
  • Looks like all the Voltage is fine on the circuit.. I also added some caps (even 2200uF not helps... ) – gabi Apr 15 '14 at 14:06
  • I added question about replacing the BJT here: http://electronics.stackexchange.com/questions/106643/replacing-bjts-with-power-mosfet – gabi Apr 15 '14 at 14:06
  • I am also think it can be the LM1117-33 regulator.. maybe when I am sinking the 400mA for the relay it has no enough power and it has "power jump" that restart the nRF24 and it loose all its properties.. I have no O'scope to check it, but I can connect it to different power source.. – gabi Apr 15 '14 at 14:08
  • 1
    Have you tried placing the capacitor after the regulator to ensure your nRF24 doesn't die? – horta Apr 15 '14 at 15:01
  • By the datasheet it said I need 10uF caps, 1 on the gnd-input and 1 in the gnd-output. I also added 25V 2200uF cap on the gnd-input.. – gabi Apr 15 '14 at 15:16
  • Sounds like you've got the power rails nicely decoupled. Another shot in the dark may be that you're getting a lot of noise from the relay. Is your relay hooked up to the 240V supply line? As in, is it turning the entire other circuit on? Switching that on with a relay would create a burst of EMI which could be messing with your transceiver. – horta Apr 15 '14 at 15:20
  • No, it still with no 240v connections.. Only the coil is connected.. – gabi Apr 15 '14 at 16:17
  • Then it pretty much has to be a power droop issue. I'm still not sure why your decoupling capacitors aren't fixing it. I doubt the mosfet switch will make a difference to the problem you're seeing because you said with LEDs it works fine. That implies there's nothing wrong with the bjt setup. The only thing different with the relay is fast drop in current you're obtaining. Here's another idea, what if you added a 5 ohm resistor in series with the relay. That would help minimize on-current which could be causing the power droop. – horta Apr 15 '14 at 17:20
  • I will check it, thanks. I will also connect the nrf24 to external power source to see if it related.. – gabi Apr 15 '14 at 18:44
2

You should be able to run the relay from either a BJT or a MOSFET. For this application the important thing to remember are; the voltage / current requirement of the relay coil, the operating voltage of your circuit and the voltage of the control signal.

When choosing components with so many parameters i usually use a suppliers parametric search feature, and input the characteristics i want from the component.

See:

BJT: http://uk.farnell.com/transistors-bipolar-bjt-single

MOSFET: http://uk.farnell.com/mosfets

For BJTs it's usually; Collector-Emitter voltage (Vce), Collector current (Ic) and Base-Emitter Current (Ibe). So in your case; Vce > 5 | VIc > 200 mA

And for MOSFETs it's usually; Drain Current (Id), Drain-Source Voltage (Vds), and the threshold Gate-Source Voltage (Vgs). So in your case; Id > 200 mA | Vds > 5 V | Vgs 5V (you want to operate in saturation)

Don't worry if for the current and voltage ratings the component you select has a much higher value, the important values are the switch on thresholds.

You can just connect the output of your uP to the gate of the FET or BJT but this is a bad idea (It usually ends in the magic smoke escaping from your expensive IC). Ideally you should have a current limiting resistor and a pull-down. You can (and probably should) calculate values for these resistors, though in practice I've found that 1k and 10k work for 99% of situations.

Here are some examples of circuits i use / have used to control relays in the past. All of these are low side switching examples, and a +ve signal from the uP will switch on the relay.

Using a NPN BJT

schematic

simulate this circuit – Schematic created using CircuitLab

Using a N-MOSFET

schematic

simulate this circuit

Hope this helps,

-- EP

  • Can you explain please how did you got the value of 1k on the base? Does the calculation is the same for FET and BJT? Also, what is the 20k resistor you have between the gatd and gnd? – gabi Apr 09 '14 at 19:48
  • The 1k & 10k values where 'pulled out of thin air' i have just found that over the years they work for most situations. – EmpiricalPython Apr 13 '14 at 14:15
  • 1
    If you remember BJTs are current controlled and FETs are voltage controlled. For BJT the base input resistor needs to be calculated such that the input current Ib is high enough to saturate the transistor. For FETs the gate voltage needs to be high enough to saturate the transistor. 'R2' is just a pull down, and also limits total input current. I'll update my answer to explain this better – EmpiricalPython Apr 13 '14 at 14:22