Author Topic: To drive 24v relay with arduino, please look at the schematic and help  (Read 5512 times)

0 Members and 1 Guest are viewing this topic.

Offline sairfan1Topic starter

  • Frequent Contributor
  • **
  • Posts: 348
  • Country: ca
I'm trying to operate relay 24v 3.0w using arduino at 3.3v, as my 3.3v circuit is going to drive a 24v relay i would say I'm going to amplify, am I correct?

I tried to learn by google around and draw two options that sounds like should work, using BD139 and BD140 transistor

In option A I'm driving transistor directly from Arduino data pin to turn ON/OFF relay using a NPN transistor Q1

In option B I'm driving a BD140 PNP Q3 transistor using a small BC series NPN transistor as in schematic Q2

If you think that should work i want to know what should be resistor values for both options and how are you calculating. If you think its not a good approach and i should use some MOSFET then please let me know I will get back with more options with MOSFET.

« Last Edit: September 16, 2021, 10:07:12 pm by sairfan1 »
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 11473
  • Country: ch
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #1 on: September 16, 2021, 10:38:10 pm »
I’d much sooner use a MOSFET for something like this. (And in fact I’m about to design a circuit using an Arduino to control some relays, and I intend to use MOSFETs to do it.)
 
The following users thanked this post: sairfan1

Offline JustMeHere

  • Frequent Contributor
  • **
  • Posts: 737
  • Country: us
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #2 on: September 16, 2021, 11:31:32 pm »
MOSFET is the way to go.  It will take an extra resistor. This resistor is 5k or 10k and pulls the gate of the fet to ground. Another resistor will protect the micro and sit between the gate pin and the micro.

When selecting a fet, choose one that is "full on" in the 2V range.  This is usually the VGS(th) in the datasheet.  You will need to check the graphs to see exactly where "full on" happens. 

Don't forget to put your flyback diode across the relay pins.

MOSFETs are preferred because they take almost no current to drive.  Your micro has a current budget. 
« Last Edit: September 17, 2021, 12:02:03 am by JustMeHere »
 
The following users thanked this post: tooki, sairfan1

Offline WattsThat

  • Frequent Contributor
  • **
  • Posts: 766
  • Country: us
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #3 on: September 16, 2021, 11:45:53 pm »
Transistors will work with the typical AtMega328 based Uno, Nano and Mega. But, if you have anything other than an AVR based processor, you will typically not have enough pin output current to drive your specific load. Since your saying it’s 3.3 volts, it’s probably an ARM based part so there you’ll need to use a Mosfet.

Why? Because you need about 10 milliamperes to drive a bipolar transistor for that relay. A mosfet is voltage controlled, not current and while it needs a bit of current at turn on, once on, it need virtually no current to remain on.

If you do have an AVR processor running at 3.3 volts, here is an answer to the question in you post:

A: R1 = 200 ohm (180 ohm okay too), R4 not critical at 10K.

B: Don’t bother. It inverts the signal, provides no benefit and just adds cost and complexity. It’s drawn upside down as well.

It’s not an amplifier. While current gain occurs, it’s not linear, it is operating as a switch and you always want the transistor to saturate, otherwise it will burn up if allowed to operate in its linear region as an amplifier.

Resistor values are easy to calculate with ohms law once you know that to operate as as a switch, you want  about 10% of the collector current to flow in the base.

To solve for R1:
3W / 24V = 0.125 amps relay coil current
0.125 * 10% = 0.0125A Q1 base current
If your drive voltage is 3.3V, subtract 0.7 for the base to emitter voltage drop. So, thats 2.6 volts.
To get 0.0125 amps at 2.6V, use ohms law R = E / I
So R = 2.6 / 0.0125 = 208 ohms. Closest 5% value would be 180 ohms, 1%, 200 ohms.

R4 not really required but 10K will keep any stray noise from possibly causing turn on when the driver pin floats, that is when neither high or low.

If you choose or need to use a mosfet, a good non-smd part is the FQP30N06L and a schematic would be:



 
The following users thanked this post: sairfan1, MarkKn

Offline sairfan1Topic starter

  • Frequent Contributor
  • **
  • Posts: 348
  • Country: ca
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #4 on: September 16, 2021, 11:56:39 pm »
Quote
When selecting a fet, choose one that is "full on" in the 2V range.

What parameter in the datasheet will describe to choose 'full on in the 2v range'

I understand you are talking about voltage applied on Gate, i saw some datasheets its bit confusing looks like they use different terms

any MOSFET you would like to recommend for this job? thanks
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #5 on: September 17, 2021, 12:04:55 am »
Option A is clearly the way to go, whether you use a BJT or mosfet.

I'm not really seeing the advantage of using a mosfet here though, it will work just fine, but so will a bog standard NPN BJT. This sort of moderately low voltage low current low side switching thing is about the least critical transistor circuit you can find.
 
The following users thanked this post: sairfan1

Offline fourfathom

  • Super Contributor
  • ***
  • Posts: 1879
  • Country: us
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #6 on: September 17, 2021, 12:11:55 am »
If you *do* decide to go with Option B (NPN transistor driving a PNP connected to the relay coil), be sure to add a resistor between the NPN collector and PNP base.  Otherwise when you drive the NPN "on" there will be nothing limiting the current flowing through the PNP base-emitter junction -- the transistors will probably burn up. 

As I see it, the only reason to use this circuit is if for some reason you want to have the relay coil be connected to ground.  Otherwise use Option A.

Or better yet, use the FET circuit suggested above.
We'll search out every place a sick, twisted, solitary misfit might run to! -- I'll start with Radio Shack.
 
The following users thanked this post: sairfan1

Offline JustMeHere

  • Frequent Contributor
  • **
  • Posts: 737
  • Country: us
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #7 on: September 17, 2021, 12:14:27 am »
Voltage Gate Source Threshold.   This is where it will start to turn on.  You need it low enough that it will be "full on".  So pick one that has a max Vgs(th) in the 2s.  The lower the better.  You will need to check the graphs and make sure 3V maxxes out the curve.
 
The following users thanked this post: sairfan1

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19494
  • Country: gb
  • 0999
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #8 on: September 17, 2021, 09:51:31 am »
Transistors will work with the typical AtMega328 based Uno, Nano and Mega. But, if you have anything other than an AVR based processor, you will typically not have enough pin output current to drive your specific load. Since your saying it’s 3.3 volts, it’s probably an ARM based part so there you’ll need to use a Mosfet.
A MOSFET is a transistor.

I'm trying to operate relay 24v 3.0w using arduino at 3.3v, as my 3.3v circuit is going to drive a 24v relay i would say I'm going to amplify, am I correct?

I tried to learn by google around and draw two options that sounds like should work, using BD139 and BD140 transistor

In option A I'm driving transistor directly from Arduino data pin to turn ON/OFF relay using a NPN transistor Q1

In option B I'm driving a BD140 PNP Q3 transistor using a small BC series NPN transistor as in schematic Q2

If you think that should work i want to know what should be resistor values for both options and how are you calculating. If you think its not a good approach and i should use some MOSFET then please let me know I will get back with more options with MOSFET.
Why did you select the BD139 and BD140? They're way overkill. The relay coil is only 3W. I = P/V = 3/24 = 0.125A.

Use the plain old BC337, in the option A circuit.

The general rule of thumb is select RB so IB = IC/10. Your MCU would have to output 12.5mA, in this case, but I consider that to be excessive. The BC337 has a minimum gain of 100, at 100mA and 60 at 300mA, when the voltage drop across the collector and emitter is only 1V. The relay is powered off 24V, so 1V of voltage drop won't be a big deal and the data sheet gives the worst case. In reality, it won't drop 1V, more like 0.1V. I'd aim for a base current of around 3mA, or so.
https://www.onsemi.com/pdf/datasheet/bc337-d.pdf

IB = 0.003A
V = 3.3V
VB = 0.7V

R2 = (V-VB)/IB = (3.3-0.7)/0.003 = 2.6/0.008 = 866 23 Ω

820R is the nearest E12 value, but even if you increased it to 1k, nearest E3 value, the lower base current wouldn't be a problem: 2.6mA will still turn it on hard enough, to power the relay.

R4 isn't really needed. It can improve the turn-off time, if the circuit is driven from a signle ended input, but in this case the MCU output has a push-pull output, which will connect R2 to 0V, when it's low. If you want to include it, use 10k.



« Last Edit: September 17, 2021, 10:08:25 am by Zero999 »
 
The following users thanked this post: sairfan1

Offline t1d

  • Super Contributor
  • ***
  • Posts: 1219
  • Country: us
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #9 on: September 17, 2021, 10:23:14 am »
Maybe not specific to your application, but a general point about MCUs and Relays. Solid State Relays are often overlooked. However, they are very easily driven with the current available straight off of a MCU pin... Meaning, less than 20mA.

They can drive DC, or AC. I have one driving my DIY reflow (toaster) oven elements with a PIC18F4550, on 7mA of current.

Yes, I know that they can be built from discrete parts... Triacs, MOSFETs, etc... But, true SSRs come in an all-in-one package with convenient connection points and some built in protection features.

Used Crydom brand units that still have lots of life left in them can be found used on Ebay. Stay away from the Fotek brand on Ebay/Amazon/AliExpress. They are proven to be dangerous junk. See Big Clive, on YouTube.

Hope that helps.
 
The following users thanked this post: sairfan1

Offline fourfathom

  • Super Contributor
  • ***
  • Posts: 1879
  • Country: us
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #10 on: September 17, 2021, 03:24:28 pm »
R4 isn't really needed. It can improve the turn-off time, if the circuit is driven from a signle ended input, but in this case the MCU output has a push-pull output, which will connect R2 to 0V, when it's low. If you want to include it, use 10k.

I would include R4, since the MCU output will probably default to high-impedance until your program configures it. 

R4 is there to prevent any collector-base leakage current from turning on the transistor when the base drive is in this high-Z state.  In practice this leakage is probably not high enough to cause problems, but R4 is a good precaution.  Yes, 10K (or 100K) would be an appropriate value.
We'll search out every place a sick, twisted, solitary misfit might run to! -- I'll start with Radio Shack.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19494
  • Country: gb
  • 0999
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #11 on: September 17, 2021, 04:46:43 pm »
R4 isn't really needed. It can improve the turn-off time, if the circuit is driven from a signle ended input, but in this case the MCU output has a push-pull output, which will connect R2 to 0V, when it's low. If you want to include it, use 10k.

I would include R4, since the MCU output will probably default to high-impedance until your program configures it. 

R4 is there to prevent any collector-base leakage current from turning on the transistor when the base drive is in this high-Z state.  In practice this leakage is probably not high enough to cause problems, but R4 is a good precaution.  Yes, 10K (or 100K) would be an appropriate value.
How much curent is required to activate the relay? If the transistor passes anywhere near enough to turn the relay on, when the MCU's output is set to high impedance, then it's bad and should be replaced.

The leakage current from the MCU will be tiny. It's only necessary to include a pull-down resistor, if it's driving a MOSFET, or perhaps a Darlington pair, but a single BJT like the BC337 will essentially pass no current. Perhaps if the BJT is directly driving a high efficiency LED, it might glow enough to be seen in a dark room, but I'd be more inclined to put a high value resistor across the LED, to stop that.
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4414
  • Country: dk
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #12 on: September 17, 2021, 05:53:06 pm »
or if driving multiples or just wanting a single all in one part, ULN2803 or similar
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 11473
  • Country: ch
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #13 on: September 17, 2021, 07:10:06 pm »
Transistors will work with the typical AtMega328 based Uno, Nano and Mega. But, if you have anything other than an AVR based processor, you will typically not have enough pin output current to drive your specific load. Since your saying it’s 3.3 volts, it’s probably an ARM based part so there you’ll need to use a Mosfet.
A MOSFET is a transistor.
You know perfectly well that in English, when someone says “transistor” in the context of discrete components, they mean a BJT. Because originally, BJTs were the only kind, so “transistor” was synonymous. (And for a long time after that, BJTs were still the overwhelmingly dominant type.) And because of that, when we mean any other kind, like a MOSFET, we name it specifically.

The only context where the word “transistor” means a MOSFET by default is when listing the transistor count in CPUs and GPUs.
 
The following users thanked this post: sairfan1, WattsThat

Offline MultiMike

  • Contributor
  • Posts: 23
  • Country: ca
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #14 on: September 19, 2021, 04:20:13 am »
Used Crydom brand units that still have lots of life left in them can be found used on Ebay. Stay away from the Fotek brand on Ebay/Amazon/AliExpress. They are proven to be dangerous junk. See Big Clive, on YouTube.

Years ago (6? 7?) I built a panel that uses a half dozen Crydom SSRs to control heaters on a machine.   That machine runs 24/5 virtually every week of the year, and some weekends.  Given the number of cycles per minute I have no doubt that each of these SSRs have cycled MILLIONS of times, and no failures.   Can't complain about that.   NOT CHEAP, but good.

Mike
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19494
  • Country: gb
  • 0999
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #15 on: September 19, 2021, 10:07:01 am »
Transistors will work with the typical AtMega328 based Uno, Nano and Mega. But, if you have anything other than an AVR based processor, you will typically not have enough pin output current to drive your specific load. Since your saying it’s 3.3 volts, it’s probably an ARM based part so there you’ll need to use a Mosfet.
A MOSFET is a transistor.
You know perfectly well that in English, when someone says “transistor” in the context of discrete components, they mean a BJT. Because originally, BJTs were the only kind, so “transistor” was synonymous. (And for a long time after that, BJTs were still the overwhelmingly dominant type.) And because of that, when we mean any other kind, like a MOSFET, we name it specifically.

The only context where the word “transistor” means a MOSFET by default is when listing the transistor count in CPUs and GPUs.
Bear in mind this is an international forum and it's the beginners section.

I accept your accusation of pedantry, but feel it was necessary in this instance. It does sound odd to read a sentence talking about transistors and MOSFETs, as though they're different things. Had he been talking about only one type of transistor, i.e. the BJT, I would have let it slide.
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 11473
  • Country: ch
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #16 on: September 19, 2021, 08:29:16 pm »
I don’t think that was necessary (or helpful) at all. I’d be surprised if many languages don’t treat the terms similarly, since the history of transistors is the same worldwide.
 

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 6961
  • Country: ca
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #17 on: September 19, 2021, 08:47:24 pm »
OP's relay is a piggy on power at 3W (125mA) coil. It's a lot of heat, you would use PWM to reduce holding current.
A single transistor you have to drive a bit hard, for an MCU output pin. I use BC817 for smaller relays. hFE is 40 at 500mA and VCE sat 1.0V

I haven't seen much for medium-high power 3.3V logic-level SMD mosfets, what parts are popular?
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #18 on: September 20, 2021, 06:25:05 am »
I very rarely hear someone say "transistor" when they mean mosfet. A mosfet is a specific type of transistor, but if someone is talking about one they'll normally call it a mosfet.
 
The following users thanked this post: tooki

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19494
  • Country: gb
  • 0999
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #19 on: September 20, 2021, 07:56:45 am »
OP's relay is a piggy on power at 3W (125mA) coil. It's a lot of heat, you would use PWM to reduce holding current.
A single transistor you have to drive a bit hard, for an MCU output pin. I use BC817 for smaller relays. hFE is 40 at 500mA and VCE sat 1.0V
The BC817 is also ideal, if you want surface mount. The minimum hFE is 250 at 100mA and VCE = 1V. It won't be much worse at 125mA. I wouldn't say it needs to be driven hard. 1mA would probably do, which isn't much for an MCU output pin.

Quote
I haven't seen much for medium-high power 3.3V logic-level SMD mosfets, what parts are popular?
I was going to say the MCH3484, but it seems to have been discontinued. I Googled and SSM3K62TU was a suggested replacement, but it has a lower current rating, which is a non-issue for this application.
« Last Edit: September 20, 2021, 12:17:34 pm by Zero999 »
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 11473
  • Country: ch
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #20 on: September 20, 2021, 11:29:24 am »
OP's relay is a piggy on power at 3W (125mA) coil. It's a lot of heat, you would use PWM to reduce holding current.
A single transistor you have to drive a bit hard, for an MCU output pin. I use BC817 for smaller relays. hFE is 40 at 500mA and VCE sat 1.0V

I haven't seen much for medium-high power 3.3V logic-level SMD mosfets, what parts are popular?
125mA is a very, very modest current for a modern MOSFET. When you consider that a modern MOSFET will have an RdsOn of under 100mOhm, the power dissipation is negligible.

I don’t know part numbers by heart, but I could look up the part I have used when I’m back in the office on Wednesday.
 

Online Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3342
  • Country: nl
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #21 on: September 20, 2021, 03:06:48 pm »
It really does not matter much for this application whether you use a MOSfet, a BJT or even a darlington.

Both an NPN and PNP transistor is also not needed, unless you have some imporant reason for wanting to switch the 24V rails instead of the GND rails.

MOS fet's generally need a pulldown to GND to prevent floating, for example during reset of the uC, and some have floating outputs in this state.
With a MOS fet it's also generally advised to use a resistor between it, and the uC, just as precaution so the FET does not kill the uC too if it ever gets damaged.
An added disadvantage of MOSfets is their sensitivity to ESD, especially when working with breadboards or before it is soldered on a PCB.

With a MOSfet you have to design in the Ugs. A lot of MOSfets simply need more then 3V3 to open them.

BJT's are current driven, and thus also need a resistor between the uC and the base of the BJT.
If you have a BJT, with an Hfe of 100 (which is still quite modest) then a 2mA base current is enough to drive a relay which needs 124mA and will saturate the transistor, and then the Collector-Emittor voltage will be at 200mV or lower.

For beginners, I advise to do both, and then measure the differences between them, and learn from it how the MOSfet and BJT's behave.

As an experiment, replace your uC with a potentiometer. a 1k potentiometer between 0V and 3V3, with a series resistor from the wiper. This is easy to build on a breadboard, and is a good starting point for learning how both MOSfets and BJT's behave in your circuit.

A word of caution for using potentiometers on breadboards:
Before you apply voltage, make sure that you can not create a short when the wiper is in any of the two extreme positions. If too much current flows through a potentiometer then the magic smoke is released and the resistance track gets damaged, and it won't work properly after that anymore.
« Last Edit: September 20, 2021, 03:14:01 pm by Doctorandus_P »
 
The following users thanked this post: Zero999, tooki, sairfan1, perieanuo

Offline MarkKn

  • Contributor
  • Posts: 39
  • Country: us
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #22 on: September 21, 2021, 11:14:13 am »
A good overview of switching mosfet circuits. https://www.microtype.io/designing-power-mosfet-circuits/
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19494
  • Country: gb
  • 0999
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #23 on: September 21, 2021, 12:32:36 pm »
A word of caution for using potentiometers on breadboards:
Before you apply voltage, make sure that you can not create a short when the wiper is in any of the two extreme positions. If too much current flows through a potentiometer then the magic smoke is released and the resistance track gets damaged, and it won't work properly after that anymore.
This is why I strongly recommend adding a series resistor, with the potentiometer, which can be instead of the one in series, with the wiper, in this case. 100R would limit the maximum current through the potentiometer to a maximum of 33mA, which isn't good, but shouldn't cause any damage.
 

Offline sairfan1Topic starter

  • Frequent Contributor
  • **
  • Posts: 348
  • Country: ca
Re: To drive 24v relay with arduino, please look at the schematic and help
« Reply #24 on: October 04, 2021, 09:01:41 pm »
@Zero999 calculations you showed in this post https://www.eevblog.com/forum/beginners/please-look-at-schematic-to-drive-24v-relay-with-arduino/msg3693538/#msg3693538 greatly helped me to understand. 

On this weekend i tried to learn further and i have a few questions

Quote
The general rule of thumb is select RB so IB = IC/10.
Please help me to better understand, IB = IC/10 how did we get 10 in the formula, is it came from datasheet? if its from datasheet can you please advise how can i find the value in datasheet. or its something standard we use for all transistors?

Quote
The BC337 has a minimum gain of 100, at 100mA and 60 at 300mA, when the voltage drop across the collector and emitter is only 1V.
Here I really want to learn how did you understand hFE
I was trying to learn how do we get hFE value from Transistor datasheet, I was trying to read datasheet of BC337, BC546 and PN2222A (hFE section of all these transistors are attached)
As what I understand hFE is a ration of current flowing between C E and B E but when i look at hFE section in datasheet it shows different unmarked (without units) ranges as MIN, MAX I do not understand,

Please refer to hFE sections of datasheet as below

for BC546 at 2mA hFE could be anything between 110 to 450? how will i evaluate hFE
for PN2222A here we have detail in a quite different way, how do i know hFE from datasheet?

Quote
I'd aim for a base current of around 3mA

How did you evaluate 3mA like if I'm doing at my own for BC546 how will I get that number?
I added two more transistors BC546/PN2222A just to better understand different scenarios
 



 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf