To drive 24v relay with arduino, please look at the schematic and help - Page 1
Forum section: electronics / beginners

author: sairfan1
author_rank: Frequent Contributor
timestamp: September 16, 2021, 10:02:22 pm
content: 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 transistorIn option A I'm driving transistor directly from Arduino data pin to turn ON/OFF relay using a NPN transistor Q1In option B I'm driving a BD140 PNP Q3 transistor using a small BC series NPN transistor as in schematic Q2If 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.

author: tooki
author_rank: Super Contributor
timestamp: September 16, 2021, 10:38:10 pm
content: 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.)

author: JustMeHere
author_rank: Frequent Contributor
timestamp: September 16, 2021, 11:31:32 pm
content: 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.

author: WattsThat
author_rank: Frequent Contributor
timestamp: September 16, 2021, 11:45:53 pm
content: 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 current0.125 * 10% = 0.0125A Q1 base currentIf 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 / ISo 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:

author: sairfan1
author_rank: Frequent Contributor
timestamp: September 16, 2021, 11:56:39 pm
content: QuoteWhat 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 termsany MOSFET you would like to recommend for this job? thanks

author: james_s
author_rank: Super Contributor
timestamp: September 17, 2021, 12:04:55 am
content: 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.

author: fourfathom
author_rank: Super Contributor
timestamp: September 17, 2021, 12:11:55 am
content: 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.

author: JustMeHere
author_rank: Frequent Contributor
timestamp: September 17, 2021, 12:14:27 am
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: September 17, 2021, 09:51:31 am
content: Quote from: WattsThat on September 16, 2021, 11:45:53 pmA MOSFET is a transistor.Quote from: sairfan1 on September 16, 2021, 10:02:22 pmWhy 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 RBso 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.pdfIB= 0.003AV = 3.3VVB= 0.7VR2 = (V-VB)/IB= (3.3-0.7)/0.003 = 2.6/0.008 = 8662⁄3Ω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.

author: t1d
author_rank: Super Contributor
timestamp: September 17, 2021, 10:23:14 am
content: 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.

author: fourfathom
author_rank: Super Contributor
timestamp: September 17, 2021, 03:24:28 pm
content: Quote from: Zero999 on September 17, 2021, 09:51:31 amI 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.

author: Zero999
author_rank: Super Contributor
timestamp: September 17, 2021, 04:46:43 pm
content: Quote from: fourfathom on September 17, 2021, 03:24:28 pmHow 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.

author: langwadt
author_rank: Super Contributor
timestamp: September 17, 2021, 05:53:06 pm
content: or if driving multiples or just wanting a single all in one part, ULN2803 or similar

author: tooki
author_rank: Super Contributor
timestamp: September 17, 2021, 07:10:06 pm
content: Quote from: Zero999 on September 17, 2021, 09:51:31 amYou 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”wassynonymous. (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.

author: MultiMike
author_rank: Contributor
timestamp: September 19, 2021, 04:20:13 am
content: Quote from: t1d on September 17, 2021, 10:23:14 amYears 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

author: Zero999
author_rank: Super Contributor
timestamp: September 19, 2021, 10:07:01 am
content: Quote from: tooki on September 17, 2021, 07:10:06 pmBear 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.

author: tooki
author_rank: Super Contributor
timestamp: September 19, 2021, 08:29:16 pm
content: I don’t think that was necessary (or helpful) at all. I’d be surprised if many languagesdon’ttreat the terms similarly, since the history of transistors is the same worldwide.

author: floobydust
author_rank: Super Contributor
timestamp: September 19, 2021, 08:47:24 pm
content: 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 useBC817for smaller relays. hFE is 40 at 500mA and VCE sat 1.0VI haven't seen much for medium-high power 3.3V logic-level SMD mosfets, what parts are popular?

author: james_s
author_rank: Super Contributor
timestamp: September 20, 2021, 06:25:05 am
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: September 20, 2021, 07:56:45 am
content: Quote from: floobydust on September 19, 2021, 08:47:24 pmThe BC817 is also ideal, if you want surface mount. The minimum hFEis 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.QuoteI 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.

author: tooki
author_rank: Super Contributor
timestamp: September 20, 2021, 11:29:24 am
content: Quote from: floobydust on September 19, 2021, 08:47:24 pm125mA 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.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 20, 2021, 03:06:48 pm
content: 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.

author: MarkKn
author_rank: Contributor
timestamp: September 21, 2021, 11:14:13 am
content: A good overview of switching mosfet circuits.https://www.microtype.io/designing-power-mosfet-circuits/

author: Zero999
author_rank: Super Contributor
timestamp: September 21, 2021, 12:32:36 pm
content: Quote from: Doctorandus_P on September 20, 2021, 03:06:48 pmThis 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.

author: sairfan1
author_rank: Frequent Contributor
timestamp: October 04, 2021, 09:01:41 pm
content: @Zero999 calculations you showed in this posthttps://www.eevblog.com/forum/beginners/please-look-at-schematic-to-drive-24v-relay-with-arduino/msg3693538/#msg3693538greatly helped me to understand.On this weekend i tried to learn further and i have a few questionsQuotePlease 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?QuoteHere I really want to learn how did you understand hFEI was trying to learn how do we get hFEvalue 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 belowfor BC546 at 2mA hFE could be anything between 110 to 450? how will i evaluate hFEfor PN2222A here we have detail in a quite different way, how do i know hFE from datasheet?QuoteHow 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

author: Zero999
author_rank: Super Contributor
timestamp: October 04, 2021, 09:44:34 pm
content: IB= IC/10 is just a general rule of thumb to ensure the transistor fully saturates, i.e. passes the desired collector current, with a very low collector-emitter voltage. Quite often the figures for the saturation voltage on the data sheet are quoted for a forced hFEof 10. This isn't always the case. Note that the BC546's saturation region is specified with IB= IC/20.Data sheets often specify hFE, with much higher collector-emitter voltages, normally 1V, 5V, or 10V, so beware, if you don't supply enough base current the voltage drop can be excessive. Fortunately the BC337's hFEis specified with a VCEof 1V, which is low enough in this application, so all you need to do is divide the load current, by the minimum hFEfigure, to give the minimum base current. Unfortunately the PN2222A and BC546 hFEratings are specified with higher collector-emitter voltages, which is why I recommended the BC337. You can use the other transistors, but need to multiply the minimum base current, calculated by their hFE ratings by a factor of two or three, otherwise the voltage drop might be too high. Look at the VCEvs IBcurves to give more of an idea of the minimum base current required.

author: gcewing
author_rank: Regular Contributor
timestamp: October 04, 2021, 11:57:04 pm
content: Quote from: sairfan1 on October 04, 2021, 09:01:41 pmhFE is a ratio of two currents, so it has no units.Yes, it varies wildly from one specimen of transistor to another. One copes with this by designing circuits so that they don't depend on hFE very much. When using a transistor as a switch, this means overestimating the required base current to ensure the transistor its turned on hard. A rule of thumb often used is to take the minimum hFE from the datasheet and divide it by 10. Use common sense, though -- don't exceed the maximum allowable base current.

author: Zero999
author_rank: Super Contributor
timestamp: October 05, 2021, 08:43:08 pm
content: As stated above the hFEvaries widely, from part to part, even of the same batch and changes with the operating conditions such as: current, collector-emitter voltage and temperature. It should not be relied upon.A BJT has three operating regions.Cut-off. no base current is supplied and the collector current is tiny, theoretically zero, but there will be some leakage.Active. The collector current varies, depending on the base-emitter voltage and current. Increasing the base current, results in a proportionate rise in collector current, depending on the hFE. For example, if a part has an hFEof 500, when VCE= 10V, then when IC= 10mA, IB= IC/hFE= 10mA/500 = 0.02mA. If the base current is increased, the collector current will increase by the same factor, so setting IBto 0.04mA, will result in a collector current of 20mA.Saturation. Beyond a certain point, increasing the base current further, no longer results in an increase in collector current, which is now mostly set by the collector load resistance. The transistor will still stop a small voltage, known as the saturation voltage. To achieve this, the base current needs to be much higher, than that in the active region.In reality, there's some crossover between one operating region and the next, as the hFEvaries. When in cut-off there should be no current, apart from a small leakage, which increases, as the base-emitter junction is forward biased. The hFEis low, at tiny currents, but increases rapidly, in the active region. Past a certain point, the hFEfalls, especially as the collector-emitter voltage drops below, the base-emitter voltage, when the collector-base diode junction starts diverting some of the base current to the collector.In short. You ideally want the transistor to be in the saturation region, when it's turned on. Unfortunately to get a really low, saturation voltage, a lot of base drive is required. IB= IC/10 is often specified on data sheets, but in reality, you can often get away with much less, in many applications. Your relay is run off 24V, so a voltage drop of 1V wouldn't be a big deal, which is why I suggested the BC337, because its hFEis specified when VCE= 1V.