Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

If I were wanting to drive i.e. industrial relays which require 24v from a Microchip PIC what would I need to look at in terms of a general transistor circuit (and it's pitfalls when driving such a component).

share|improve this question
1  
'Controlling a relay from a microcontroller' This question has been asked so many times here. Steven, Olin.. are you in for a nice canonical answer? :-) – m.Alin Aug 16 '12 at 17:16
Apologies if this is repeat (I did do a search but was too specific I think) – Paul Sullivan Aug 16 '12 at 18:00
2  
1  
@m.Alin - you're right, it needs a canonical question/answer that includes things like a discussion of the transistor specs and the inductive factor. It's certainly a popular one, I recall answering quite a few similar questions. – Oli Glaser Aug 17 '12 at 3:54
Will do @stevenvh - It will also give me some time to digest your answer (much appreciated btw) and some of it's intricacies :) – Paul Sullivan Aug 17 '12 at 16:28

4 Answers

up vote 6 down vote accepted

I'm sorry, but I think Matt's answer is not a good one at all.

The MOSFET in his schematic is a P-channel, not an N-channel. The diode doesn't offer any protection for the FET; it may be destroyed together with the FET. Besides it's a 20 V diode, so even if it would protect against the induction voltage the 24 V supply may already kill it. The 7406 is superfluous, besides its maximum voltage is 30 V, not 40 V, and that 30 V is Absolute Maximum Ratings, not for continuous use. The circuit will also draw an unnecessary 5 mA with the relay on, and 10 mA no less with the relay off. Also the 100 Ω resistor doesn't "dampen oscillations".


What you need is a logic level gate MOSFET. You're using a PIC, which probably will have a supply voltage of minimum 3.3 V. Let us know if the voltage is lower. A logic gate FET will switch on with a 3.3 V gate voltage, so the PIC can drive it directly. No 7406 needed.

A relay typically needs less than 500 mW, at 24 V that would be 20 mA, but this is an industrial relay, and will probably need more. Let's be generous and say it needs 1 A (that's 24 W!). If we can find a FET with an \$R_{DS(ON)}\$ of less than 350 mΩ we'll be able to use an SMD; these are much cheaper than PTH parts. At the high 1 A it will dissipate 350 mW. What else? Power supply is 24 V, so let's take a maximum \$V_{DS}\$ of minimum 40 V. One FET which fulfills these requirements is the BUK98150:

Max. \$V_{DS}\$ 55 V
Max. \$I_D\$ 5 A
Max. \$R_{DS(ON)}\$ < 200 mΩ @ 3.3 V
Max. \$V_{GS(th)}\$ 2 V

Looks good. The BUK98150 will sink 2 A at 2.6 V gate voltage.

enter image description here

This graph shows an \$R_{DS(ON)}\$ of 175 mΩ @ 3 V and 2 A, for 1 A it will be less. Then dissipated power will be 175 mW, which the SOT-223 package can handle easily. The 175 mV drop is negligible.

enter image description here

This is the circuit. Contrary to Matt's it only consumes 0.1 mW. I've kept his 100 Ω resistor, which limits the short current spikes when switching; a microcontroller doesn't like capacitive loads much. The 100 kΩ ensures that the gate won't float if the PIC's I/O would be switched to input accidentally.

As you can see the diode goes over the relay, not the FET. You can use a Schottky diode here. This one has a maximum reverse voltage of 40 V.

share|improve this answer
Only question and it's really an 'aside'. Choice between p-n diode and Schottky is purely due to high frequency capability of the Schottky? If the lag in a p-n diode is irrelevant then p-n is fine? I don't see a reason why you would need a Schottky as a flyback (correct my ignorance if you will) – Paul Sullivan Aug 17 '12 at 17:49
and, and, and... how does anyone find components with specific characteristics so quickly (just experience or are there specific places you look?) – Paul Sullivan Aug 17 '12 at 18:03
@Paul - Schottky's have a faster recovery time, but that's actually only relevant if you want to switch on quickly after switching off. In most cases for low currents a 1N4148 or for a bit higher a 1N400x will do. A Schottky also has a higher leakage current, esp. at higher temperatures, but still will be only a fraction of what the relay needs, so no worries. Always check the reverse voltage, though: for Schottky's that's often more limited. – stevenvh Aug 17 '12 at 20:47
@Paul - I almost always use the selection tools on the Digikey site. Of course you have to understand what different parameters mean to be able to select a value or range for them, and that's experience. More often than not you still have enough parts to choose from, and then it's browsing through a couple of datasheets. Digikey has links to datasheets for 99.999999999 % ;-) of their parts. (Just one or two missing, that is) – stevenvh Aug 17 '12 at 20:51
thanks @stevenvh I was going to use a 1n4001 though I will check it's specs properly and make sure I'm not over stressing/volting. I will bookmark digikey. Thanks a lot for your help I have to say you are an ambassador (having seen your major contrib on many other questions) to electronics.stackexchange. Much appreciated – Paul Sullivan Aug 17 '12 at 22:02

I would do something like this.

enter image description here

Use an N channel MOSFET and a 7406. The reason I say 7406 is it is an open collector part and can sink 40mA, and tolerate 40V. It will also provide your uC some isolation from the 24V circuit.

When a logic 0 goes into the 7406, the output transistor is off, showing high impedance to the rest of the circuit. R2 and R3 form a voltage divider providing 12V to the MOSFET gate. Check your MOSFET's maximum Vgs to set these values.

When a logic 1 goes into the 7406, the output transistor turns on, showing a path to ground. The output will actually be around 0.7V, but that isn't nearly enough to turn on the MOSFET. 10mA will flow through R2, safe for the 7406, but that resistor is going to get warm if it's a typical 1/4W resistor. The MOSFET will turn on, energizing and closing the relay.

A couple other notes:

R1 is there to dampen the oscillations as the MOSFET turns on. It forms an RC circuit with the parasitic gate capacitance. For this application, you could eliminate it, but for higher speed applications, it is good to have.

D1 is Schottky diode, and is needed for flyback protection. Inductive loads generate a flyback voltage, because of L*di/dt. Flyback voltage will kill a FET in a heartbeat.

A logic level MOSFET would work fine here, but I prefer this configuration since it is more easily scalable to large power transistors.

share|improve this answer
Matt - thanks for the detail. This is exactly what I was after :) – Paul Sullivan Aug 16 '12 at 18:05
What is the advantage of the 7406 versus adding another transistor (such as Bipolar or MOSFET)? – Michael Pruitt Aug 16 '12 at 22:02
This is one of my little library circuits I keep filed away to memory. It's a quick and easy way to a PLD to almost any power transistor set up. – Matt Young Aug 16 '12 at 22:45
It's a quick and easy way to connect a PLD to almost any power transistor set up. Its input is logic level. Keep in mind, the 7406 only works up to 40 V. If you have a need for high voltage, another transistor becomes necessary, as well as optoisolation of the PLD. If you put a BJT in the 7406's place, you need to be sure it can be driven to saturation by the PLD output. Unless you were using a logic level MOSFET, the PLD would probably not be able to turn a MOSFET on all the way. If you can a logic level MOSFET, the 7406 would be unnecessary anyway. – Matt Young Aug 16 '12 at 22:54
-1 for a zillion reasons. See my answer for details. – stevenvh Aug 17 '12 at 7:52
show 2 more comments

I recently did something very similar to this as a beginner, and found MOSFETS very useful. You need a 24V source from somewhere to switch your relay, which should be connected across the drain-source pins of the MOSFET. You apply a voltage to the Gate pin (using the pinout from your PIC), and this essentially switches the relay-driving circuit on.

I made the mistake of taking the gate-threshold voltage in the datasheets as the voltage required to fully turn it, so rather than worrying about this it's much easier to just get a logic-level MOSFET, such as the IRL520. You need to make sure that it's capable of switching 24V and whatever current your relay will draw.

You also need to connect a diode in parallel with the relay to prevent damage to the transistor when it switches.

share|improve this answer

A very simple and integrated solution may be the NUD3160. Basically the same footprint as a discrete MOSFET or transistor but with inbuilt protection for both the input and output.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.