User avatar
ameador1
Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

How best to control higher voltage relays with 12v/24v coils?

Fri Mar 29, 2019 8:08 pm

I think I have determined that a power switching solution I'm working on will require DPST/DPDT relays. Power draw is 240V/5 to 6amp continuous. Not motors (well, there are relatively small cooling fans). It is computer equipment. I want to be able to use RPi to turn these units on/off. I think I have settled on some 12v coil relays that match the power specs I need. But, they have coil PSU connectors for 12v + and +. So, I cannot control these by simple GPIO HIGH/LOW signals.

What might I use to control the coil power to these relays? I could use relay boards that are controlled via GPIO. Like, for example, by turning on relay 1 on the smaller SPDT relay board. This would then close the power connectors which in this case would be a 12v power source - that in turn close the coil connections on the bigger DPDS relay 1 - turning on my device - and vice verse.

But, this feels like a cludge! Adds extra parts in the system to fail. Is there another better way? Thanks!
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

blimpyway
Posts: 83
Joined: Mon Mar 19, 2018 1:18 pm

Re: How best to control higher voltage relays with 12v/24v coils?

Fri Mar 29, 2019 9:13 pm

You can either
- look for relay modules which beside the relays themselves include whatever circuitry is needed to drive them with 3.3 or 5V low power signals, so they can be commanded directly

- look for components/schematics which interface between PI's gpio lines and 12 or 24V relay coils.

Most infos and tutorials you can find about interfacing/driving relays with microcontrollers (e.g. Arduino) apply to raspberry pi too.

User avatar
NGC6543
Posts: 75
Joined: Thu Feb 28, 2019 7:30 pm
Location: Lancashire, UK

Re: How best to control higher voltage relays with 12v/24v coils?

Fri Mar 29, 2019 9:49 pm

There certainly are better ways if you're open to some soldering. I would use an opto coupler to drive a MOSFET, to drive the relay. Alternatively you could use a MOSFET photorelay which is an optocoupler with a MOSFET 'output' in one little package. For instance the TLP172A will happily run off a GPIO with a small resistor and the output side can handle 400mA for your relay coil. Search for the datasheet.

The separate components solution would look something like this:
rl1.jpg
rl1.jpg (65.81 KiB) Viewed 1159 times
Just a side note: If you are powering computer SMPS's that run at 6A (sounds like a server), they could have a whacking great inrush current when powered up. Check the PSU's documentation for that, and make sure the relay you choose can handle it without welding. Also, do not be tempted to use a SSR (solid state relay) instead of a 'proper' relay because they leak a little current and will gradually cause the PSU to charge up.

User avatar
ameador1
Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

Re: How best to control higher voltage relays with 12v/24v coils?

Sat Mar 30, 2019 1:56 am

Thanks for the detailed response NGC6543! I looked up the components and it looks like the TLP172A is cheaper than buying the other parts - so I think that's the way to go. I don't mind soldering - I just wish I was more of an electrical engineer lately :)

The docs I found actually refer to the package as a SSR (the TLP172A). So in essence it's still powering the high voltage relay with a smaller relay - but simpler and better suited to the project at hand. I like it.

Would you still recommend the same 680ohm resistor paired with the TLP172A?

Are there any other packages that you are aware of that have a batch of these TLP172As in a dip form for like 8 or 16 of them? That would be cool!
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

klricks
Posts: 6445
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: How best to control higher voltage relays with 12v/24v coils?

Sat Mar 30, 2019 2:24 am

I have used a SSR Opto 22 model 240D45 (24VAC to 280VAC up to 45A) 3-32VDC trigger. http://documents.opto22.com/0859_Solid_ ... _sheet.pdf
These have opto isolators built in and can be directly driven by the RPi GPIO without any additional circuitry.
Note that some of the cheap Chinese copies do not work without adding a transistor circuit to switch them with 5V.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

User avatar
ameador1
Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

Re: How best to control higher voltage relays with 12v/24v coils?

Sat Mar 30, 2019 3:39 am

I couldn't find any of their models that appear to be DPST or DPDT - unless I'm missing something...
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

klricks
Posts: 6445
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: How best to control higher voltage relays with 12v/24v coils?

Sat Mar 30, 2019 4:05 am

ameador1 wrote:
Sat Mar 30, 2019 3:39 am
I couldn't find any of their models that appear to be DPST or DPDT - unless I'm missing something...
If you are in US and prefer to switch both legs of the 240V then that would require 2 (SPST) SSR's
I have never seen DP SSR's but haven't looked.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

User avatar
ameador1
Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

Re: How best to control higher voltage relays with 12v/24v coils?

Sat Mar 30, 2019 1:24 pm

Yes, I am in the US and need to cut both legs when the relay is triggered. The other issue is price. I can't put much into this and I have 16 of these devices - in this scenario I'd need 32 of these SSRs which would be pretty costly. I'm also very leary of using independent relays per leg - these units become problems with only one leg closed. They really need both legs reliably cut.
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

User avatar
NGC6543
Posts: 75
Joined: Thu Feb 28, 2019 7:30 pm
Location: Lancashire, UK

Re: How best to control higher voltage relays with 12v/24v coils?

Sat Mar 30, 2019 7:43 pm

First... the problem with using big SSRs to switch the PSUs directly is that the SSRs leak current when off and connected to an AC supply. This is because they contain a snubber circuit on the output. This leakage will slowly charge the capacitors in the PSU and cause it to cycle on every time the charge gets high enough. I know this because I've seen it happen ;)

SSRs have their place, but it's not controlling SMPSs. Powering a relay from an SSR (either the big ones, or a TLP172A which has no snubber) would be OK because relays don't care about a tiny leakage.

The TLP172A should have negligible leakage. While they are referring to it as an SSR, it's different to those big SSRs.

I might change the resistor to 430R instead of the 680R for the TLP172A to give about 5mA. I notice that the spec sheet gives an output resistance of 1 to 2 ohms at 5mA LED current. By the way, it seems that part is end-of-life so supplies might be hard to come by. You might need to find another. Well, it has been some years since I was really involved in electronics :lol:

By the way, DPST and even 4PST SSRs are available - I have a load in my loft :D for example TD2420Q

User avatar
ameador1
Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

Re: How best to control higher voltage relays with 12v/24v coils?

Sun Mar 31, 2019 5:13 am

Hey NGC6543, would it be possible to use these Darlington arrays? https://smile.amazon.com/Toshiba-ULN280 ... 263&sr=8-4

It takes low voltage (3.3v from GPIO) on the low side and says it can supply 500mA on the output side at up to 50V. I have already found some magnetic relays that are rated for my load that have a 12v coil. So I have a test batch and a 12v PSU on the way.

If this would work, I'd only need two of these DIPs to control 16 relays. Cheaper than the TLP172A (price that I've found x 16) and seemingly capable. What do you think?
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

lawsonkeith
Posts: 12
Joined: Mon Jun 30, 2014 8:11 pm

Re: How best to control higher voltage relays with 12v/24v coils?

Sun Mar 31, 2019 12:41 pm

Hi

Why not but a relay module from ebay? They are usually optically isolated so can be run off the PI GPIO, you can use those relays direct (240V/10A contact rating) or parallel them up (10A x n) or use them to switch a more powerful relay (if you're turning on a huge load). If you get a 5V model you can power it off the 5V pi PSU (this powers the coil) but switch it with the lower GPIO voltage of 3V3.


You can use the darlington driver to drive your coil - but using a relay module of ebay would be cheaper / easier. For the darlington option it's a low side switch so bear that in mind switching 5V would end up being 3.8V at the coil due to the volt drop across the darlingtons. If you powered the darlington off of 24/12V though it wouldn't matter so much. The main advantage of doing your own is that those cheap relay modules are of unknown quality really, if you buy a propper 24V industrial you know it'll still be going in 10 years time. Bear in mind if you're using 24/12V there's a lot more energy at that voltage level - so you need to make sure your wiring is good otherwise you'll be going through a lot of PIs!

Chinese relay module:

User avatar
NGC6543
Posts: 75
Joined: Thu Feb 28, 2019 7:30 pm
Location: Lancashire, UK

Re: How best to control higher voltage relays with 12v/24v coils?

Sun Mar 31, 2019 1:26 pm

ameador1 wrote:
Sun Mar 31, 2019 5:13 am
Hey NGC6543, would it be possible to use these Darlington arrays?
Yes, but you have no optical isolation with those. Plus they'll drop about 1.4V from your relay supply but that shouldn't stop your relays working. I would feel uncomfortable with not having the isolation myself. Things do occasionally fail and if you have optoisolation, at least the Pi is safe from a driver failure. Your choice though, optoisolation isn't essential to the actual function.

ULN2803 are technically TTL parts, but work down to 3V at lower output current (still enough though). Don't use a resistor to the GPIO pin.

Bear in mind the power dissipation... get your relay coil currents from their info, multiply by 8 for the number of drivers, and by 1.4 for the voltage drop. The ULN2803 has a maximum total dissipation of 2.25W. It will start getting hot at half of that though. Should be OK unless your relays are particularly hungry. (E.g. for 50mA relay coils: 0.05 * 8 * 1.4 = 0.56W. No worries.)
Last edited by NGC6543 on Sun Mar 31, 2019 1:38 pm, edited 1 time in total.

User avatar
NGC6543
Posts: 75
Joined: Thu Feb 28, 2019 7:30 pm
Location: Lancashire, UK

Re: How best to control higher voltage relays with 12v/24v coils?

Sun Mar 31, 2019 1:33 pm

lawsonkeith wrote:
Sun Mar 31, 2019 12:41 pm
you can use those relays direct (240V/10A contact rating) or parallel them up (10A x n)
Do you mean to connect multiple relay's contacts in parallel to increase the current handling?

Don't do that!

There will always be one contact that closes a bit quicker than the others and takes the hit... it will fail, possibly welded. (assuming it is actually carrying enough current to make you think you need to parallel them.)

It's like paralleling diodes to increase current handling... one will always have a slightly lower Vf and take the load, failing with a 'pop' :o ... followed quickly by successive diodes as they get the load. POP POP POP!!!

lawsonkeith
Posts: 12
Joined: Mon Jun 30, 2014 8:11 pm

Re: How best to control higher voltage relays with 12v/24v coils?

Sun Mar 31, 2019 2:44 pm

Hi

No that's not what I meant. So it's a 5-6A load and most budget relays state a 10A contact rating at 250VAC - problem sorted?

If in the future he wants to add another load i.e 10-12A in total then add another relay to supply the other load then the contact ratings aren't exceeded per contact. i.e 2 relays each supplying 5-6A well within the 10A contact rating and therefore no contacts are getting welded in.

I would say though if its used a lot I'd get a branded relay coil of one of the major distributors. You can then fire that with a darlington array as discussed here:

https://www.microcontroller-project.com ... llers.html

User avatar
NGC6543
Posts: 75
Joined: Thu Feb 28, 2019 7:30 pm
Location: Lancashire, UK

Re: How best to control higher voltage relays with 12v/24v coils?

Sun Mar 31, 2019 5:12 pm

lawsonkeith wrote:
Sun Mar 31, 2019 2:44 pm
...then add another relay to supply the other load then the contact ratings aren't exceeded per contact.
That makes sense now. No more nightmares about welded contacts on one leg of the supply causing havoc :lol:

I agree on using known quality relays from a reputable supplier, especially for an SMPS that draws 6A running and so far unspecified inrush current. I would not trust those cheap Chinese relays for anything serious.

User avatar
ptimlin
Posts: 87
Joined: Tue Jan 08, 2019 7:44 pm

Re: How best to control higher voltage relays with 12v/24v coils?

Sun Mar 31, 2019 8:18 pm

If I might make a suggestion. Will use Digi-Key links but you can probably find these parts elsewhere...

ULN2003LV (must be the "LV" version to interface directly with the Pi GPIO) are 70-cents and can drive 7 relays.
https://www.digikey.com/product-detail/ ... ND/3283552

If you want to work with something easier to solder wires or with a solderless breadboard, then pick up this dirt cheap adapter which accepts up to 28 pin SOIC/SOPs for $1.04 each...
https://www.digikey.com/product-detail/ ... ND/6588425

Any unused pins on that adapter board you can solder other things onto/across. Just this week I used one of these for a circuit that used 2 Opamps and 1 comparitor all in 8 pin SOIC packages and I was able to put all three on this little board leave two pins on each side that I used to bring in +/- 15V for all three.

The ULN2003LV does have a couple drawback that need to be noted. First, the common pin that ties to your high side voltage (the side that would drive your relay coil), has a max of 8V. So you would have to go with +5V relays. Or you could simply use these as a low cost voltage and current boaster to drive something else, say one of those ready made +5V input relay boards from eBay. Also keep in mind these types of ICs, like the ULN2803 linked earlier, all the output inverters/buffers when they go low are referenced to the ground pin of the IC. Meaning, if you turn on 3 output at 100mA each, then you have 300mA going to the ground pin. So in the case of the ULN2003LV, the max for under 100C is 1A, 700mA if temperature is higher. So you are really limited by the ground pin for how much you can sink through all 7 channels.

That said, one advantage of these ICs is you can drive a load with more than one of these to increase current and spread the load. You could hook up all 7 output to a single relay coil and be able to easily drive a coil requiring up to 0.7 amps. Also another consideration is that the input current to drive the inverter on these is tiny. While the Pi's GPIO can supply 16mA per pin, I believe there is a total GPIO port current budget is something like 51mA? I think many people might miss that little tidbit and if you drive, say 3 LEDs and a coil, you can quickly eat up that current budget even though you have a bunch of GPIO pins left over. So with one of these you can offload the current drive from the Pi to the UL2003LV and easily use ALL your GPIO pins within the total current allowance.

Anyway, thought I would mention these two pieces (the IC and the adapter board) because for under $2 (ignoring things like minimum buy without a surcharge and shipping charges) as they are a very affordable way of "level shifting" from 3.3v to 5v and giving good current for anything that needs to be powered with a bit more oomph than a Pi GPIO pin can handle. They are also easier to interface without much additional external components required for many applications.

lawsonkeith
Posts: 12
Joined: Mon Jun 30, 2014 8:11 pm

Re: How best to control higher voltage relays with 12v/24v coils?

Mon Apr 01, 2019 5:46 pm

We used some of the cheap relays where I work - they failed within 2 wks. When you read the product reviews a few people complained about the same issue and the same time frame. I think you get what you pay for really with relays.

If it's powering 6A I'd pay the extra money and get something you know you can rely on since the worst case scenario could end up being fire / electrocution.

RS have a good range, if you get one with spade connectors on it should be easy to wire, if you use a PCB and stripboard you need to check the current carrying capacity of your copper tracks and terminal blocks.

https://uk.rs-online.com/web/p/non-latc ... s/2111269/

44mA to fire the coil at 12V. 10A contact rating.


.

User avatar
ameador1
Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

Re: How best to control higher voltage relays with 12v/24v coils?

Wed Apr 03, 2019 2:04 pm

Sorry for disappearing! Busy weekend and my daughter is in town from college.

Thanks for the info - I will have to look into all this and try to absorb it :)

I'm sure I'll be asking more in a few days! Thanks again! :)
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

pcmanbob
Posts: 6256
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: How best to control higher voltage relays with 12v/24v coils?

Fri Apr 05, 2019 9:50 am

The ULN2003LV does have a couple drawback that need to be noted. First, the common pin that ties to your high side voltage (the side that would drive your relay coil), has a max of 8V. So you would have to go with +5V relays

If you want to drive 12 or 24V relays switch to a ULN2803A

The ULN2803A device is a 50 V, 500 mA Darlington
transistor array. The device consists of eight NPN
Darlington pairs that feature high-voltage outputs with
common-cathode clamp diodes for switching
inductive loads. The collector-current rating of each
Darlington pair is 500 mA. The Darlington pairs may
be connected in parallel for higher current capability.
You can drive it directly from the pi gpio if you use the " A " version
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
ptimlin
Posts: 87
Joined: Tue Jan 08, 2019 7:44 pm

Re: How best to control higher voltage relays with 12v/24v coils?

Fri Apr 05, 2019 3:24 pm

The ULN2803A could work as well. The thing to keep in mind is that this one is a Darlington configuration so you might lose as much as a voltage on the output so that when you pull the output low it may only get down to 1V or so when pulling a hundred milliamps or more. So keep that in mind of driving a device that needs less than volt input to be a true "low".

User avatar
ameador1
Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

Re: How best to control higher voltage relays with 12v/24v coils?

Fri Apr 05, 2019 7:41 pm

Ok, I think I have looked into this stuff enough to have some good thoughts and questions again.

I had asked earlier about the ULN2803A - So I think from @pcmanbob and @ptimlin, that this is an option. But, I also do like the earlier suggestion of using optocouplers to protect the pi. So, I was looking around and found this item https://www.digikey.com/product-detail/ ... ND/4562956 But, honestly - I am too uneducated on the electronics side of this to know for sure what I am reading. I think I get that this is effectively both an optocoupler as well as a Darlington array. But, I'm not sure exactly what the point is in the Darlington array at this point. @pcmanbob had helped me on an earlier discussion where I did end up using a ULN2908A to control one of those 8 channel relays off Amazon that really seemed to work better at 5v vs 3.3v and this was a way to get some isolation and converted the signaling to active high instead of active low. But, in this case, it's a different scenario and now I don't know that I see the point in it - especially if optocouplers are in the mix.

I mean, at this point I think I am set on controlling the 12v power to the DPDT relay's coils to turn them on/off. So, in that case I can just control the optocouplers with the pi and it seems to me that they are capable of handling the 12v power for the relays on their own on the other side. But, I would prefer to find them in a DIP package with 4 or 8 of them per DIP so as to simplify board design and lower costs. In the process of looking to some of these, I came across the item I linked.

It is a good priced - but has the Darlingtons in it. I don't suppose that hurts anything and seems to increase the capacity of what these DIPs can control - fine. But I started thinking more about a power issue with the pi. I want to control 16 of these relays at one time. So, that means powering 16 of the optocouplers. I'm not able to understand the specifications given on this item to know if that is feasible.

My understanding is that on the pi 3B+, that all GPIOs combined can only output a total of 51ma. I think on the datasheet for this item - that the LED on the pi side of this is using 10ma - at least in their "Test Condition" on the top of page 3. It also says the Min forward voltage is 1.1v - so maybe 10ma is not needed and can go lower? But that is one of my other issues - I don't know how to run the calculations on these things. I'm such a frustrated noob!

So, anyway, I do think I want to use optocouplers if able to. I do need all 16 relays to be engaged at one time. I plan to use 12v to power the coils on the relays. Will probably design and have a PCB fabricated for the components that will use a ribbon cable to the pi and will use screw terminals to make connections to the relays which will be socket-based DIN rail mounted relays (DPDT)

I would love some explanation or to be pointed to explanations on how to calculate things - like resistor sizing between GPIO and other components, what values to specifically look for on these data sheets so I know what data point to use in calculations, etc... I'm willing to learn - but I'm been looking at YouTube videos, web searches, tried looking for book titles and nothing seems to be hitting the spot. Really looking for how to figure this stuff out in relation to circuit design with RPis, Arduino's, MCU's in general, etc.. So much seems overly simplified. They don't give the design calculations or how/where to check with meters to see if things are correct or for detecting a failure. General electronics books don't deal with these MCU particular considerations - and still, seem weak on design theory.

I had some electronics training many, many years ago - so like the idea of what the basic components do - I get (i think ;) ). But when it comes to combining them and getting the math worked out - it's just not there - and it never made sense to me even way back when. I always had a disconnect between how to develop designs vs being told how to do the simple math on simple schematics with given data vs - coming up with the data and making the schematic.

Sorry to ramble - again - I appreciate the help with this!
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

lawsonkeith
Posts: 12
Joined: Mon Jun 30, 2014 8:11 pm

Re: How best to control higher voltage relays with 12v/24v coils?

Fri Apr 05, 2019 8:34 pm

Hi

1. I don't think you need optocuplers what are you protecting the PI from? the relay is already a form of isolation. If you are dead set on them the el cheapo relay boards already have them fitted. Optos are generally best avoided. I wouldn't recommend cheap relays either.
2. The ULN2003/2803 is ideal, it's even got a flyback diode built in!
3. If you're using an amazon board you just run it direct of the GPIO, no additional electronics required.
4. The 2803 can drive up to 0.5A per darlington, practically the thermal dissipation will limit it . You'll be fine unless the relays are huge. The current gain is 1000 so if all the relays are on and they're pulling 1A in total the Pi would be supplying 1/1000 = 1mA.
5. Forget about optos, they waste current and are expensive and you don't need them.

Just buy:
1. stripboard
https://uk.rs-online.com/web/c/pcb-prot ... oards-pcb/
2. Some terminal blocks:
https://uk.rs-online.com/web/p/pcb-term ... s/1444330/
3. a couple of ULN2803a
https://uk.rs-online.com/web/p/darlingt ... s/1686833/
4 relay
https://uk.rs-online.com/web/p/darlingt ... s/6868209/

Back of fag packet calcs:
200mw coil @ 12v = 16mA x 8 relays = 128mA. With a gain of 1000 you Pi will be supplying 0.1mA via GPIO. Loads less than with optos.
Temp of IC = 0.9V (darlo) x 128m x 70 DegC/W = 7 degree rise above ambient.

Just but the gear and start doing some testing. If you don't want to do any electronics buy the relay blocks and pray you are lucky.

User avatar
NGC6543
Posts: 75
Joined: Thu Feb 28, 2019 7:30 pm
Location: Lancashire, UK

Re: How best to control higher voltage relays with 12v/24v coils?

Fri Apr 05, 2019 9:09 pm

I would not do this without optocouplers to the Pi and I don't see why they are 'best avoided'. They are there to protect the Pi from the 12V switching a lot of relays circuit. The relay isolation protects the switching board (and everything else) from the mains side. Still, I worked in high availability systems so maybe I'm paranoid. Without optocouplers, a fault could well kill the Pi and everything goes off. With them, with a bit of luck only one channel goes out and needs repair.

------------------

Anyway, here's my two cent's worth with some ohm's law stuff and how to use the datasheets:

That part, the TLP291-4, is a quad optoisolator but not with Darlington outputs. It would do the job of four of the 4N25 parts in my first diagram. You would still need the MOSFETs to switch the relay current (or bipolar transistors but I think MOSFETs are better for the purpose). I'll give you some more info on things at the end.

From a quick look at the datasheet, you don't need 10mA LED drive. The minimum Vf of 1.1V just means that is the minimum voltage it will drop if you give it 10mA. It varies from device to device, hence the range given.

Since you need to control 16 relays, we need to be careful how much current we allow each driver. 2.5mA each adds up to 40mA all on, which leaves us some wiggle room.

From the If-Vf graph on the datasheet, if we aim for 2.5mA LED current, that gives an LED voltage drop of 1.1V at 25 Celsius. Since the Pi is 3.3V, we need to drop 3.3-1.1=2.2V on the resistor, with 2.5mA current. Ohm's law says R=2.2/0.0025=880. Nearest standard resistor is 910 ohms for R2 in my diagram. Good enough.

The Ic/If-If (transfer ratio) graph says that 2.5mA LED current will give up to 108% of that as the maximum 'output' current. 2.7mA. Not much but that's why it's nice to use a MOSFET next so it doesn't really matter.

We need to pull the MOSFET down several volts (at least -4 from the MOSFET datasheet) below the supply to switch it on. Whatever resistor we use for R1, that needs to drop enough from the supply voltage to do that, with the above 2.7mA. Whatever we work out will give us a minimum value here for that resistor; higher won't hurt as long as we keep a little current flowing. If we say we pull down all the way to ground, from 12V, that gives us 12/0.0027=4444 ohms. I would slap a 4.7k in and call it done.

We could probably drop the LED current to 2mA or even 1mA; another look at the datasheet graphs show little difference really. I would want to test it at 1mA to make sure, but it should do. If we did... and picking some slightly different figures from the graphs for LED Vf and Current Transfer Ratio to account for the 1mA:

R2 = (3.3-1.0) /0.001 = 2300 ohm
R1 (minimum) = 12/0.001 = 12 k ohm

------------------

Some info on Darlingtons and MOSFETs:

Darlingtons are two bipolar transistors connected internally so as to give much more current amplification. Hence the ULN2803A can drive a relay itself from the same few mA input, but the TLP291-4 cannot because it's a single transistor on the output. Darlingtons are also often designed with a 'larger' output transistor, anticipating that it will be driving something more powerful.

The drawback with a darlington is it drops 1.2V to 1.4V across itself when on, which takes away from the relays and consumes power that can make the chip hot. None of that is a killer as long as you account for it. It really depends on your relay current whether the ULN2803A is suitable (too much = overheating).

MOSFETs don't drop a specific voltage when on, but instead have a resistance. So, the voltage drop depends on the current going though them. Q1 in my diagram has a 0.175 ohm resistance when fully on. A 150mA relay then would cause a voltage drop across the MOSFET of only (by Ohm's law) 0.175*0.15=0.027V. The power it dissipates would be 0.027*0.15=0.004W. Not worth thinking about. The above darlington example with the same relay would dissipate 1.2*0.15=0.18W. Not much still, but way more than the MOSFET and enough to have to think about, especially if you have eight of them in a small ic.

Given that the power the device dissipates (and how hot it gets) depends on the current * voltage drop, you can see that the MOSFET is far better than the Darlington at that.

Also, MOSFETs don't need an 'input current' into the base the way a bipolar transistor does. Instead they work just off the voltage level at the gate terminal. So we can use low current outputs, with a resistor to set the voltage, instead of having to think how many mA we need to drive them with.
Last edited by NGC6543 on Sat Apr 06, 2019 10:28 am, edited 4 times in total.

User avatar
NGC6543
Posts: 75
Joined: Thu Feb 28, 2019 7:30 pm
Location: Lancashire, UK

Re: How best to control higher voltage relays with 12v/24v coils?

Fri Apr 05, 2019 10:13 pm

Just to add: you could make do with much cheaper MOSFETs than the one I put in the diagram. That was just an example really to get us going, given that I didn't know much of your requirements (and I'm not up on MOSFET part numbers any more but was using that exact part myself that day).

You just need to have these specs as a minimum:

Must be a P-channel MOSFET (not N).
Vdss: Breakdown voltage: More than your PSU including any possible surge.
Vgss: Higher than the PSU ideally, including possible surge. +-20V is common. Otherwise we need to use a potential divider to limit the voltage on the gate, instead of a single resistor.
Vgs threshold: That's the turn-on voltage (measured from positive supply since it's a P-channel). -2V to -4V or so is usual and not critical at all with how we are using it.
Current: depends on your relay, but Power MOSFETs tend to be rated in amps or tens of amps, not mA :)
RDS(on): The 'on' resistance: Anything less than an ohm will do, typically they are milliohms.
Power Dissipation: More than your relay current * RDS(on). Again, most will be easily capable for this.

MOSFETs are often listed as voltage/current (e.g. 60V 20A). That gets you close but you still need to then check the Vgs mostly, and other details. There are far more that can do what you need, than not. It's just finding a cheap one.

There are other aspects to MOSFETs of course, for instance the time it takes to turn on depends on how much current the gate can get. While it doesn't pass current like the base of a bipolar transistor, it acts like a capacitor that must be charged (and discharged to turn off). That's not an issue turning on/off relays occasionally though.

User avatar
ameador1
Posts: 89
Joined: Fri Feb 22, 2019 5:43 pm
Location: Eastern - USA

Re: How best to control higher voltage relays with 12v/24v coils?

Sat Apr 06, 2019 12:49 am

Wow @NGC6543! Thank you for the detailed reply! Now - I have admit I don't understand about half to a 3rd of it. But, I'll re-read it while looking at the data sheets to see if I can wrap my head around it. Some of it is terminology I'll look at as well. I could have sworn the units I linked were opto-darlington combos and the one I'm thinking of did have two transistors, a resistor, and a diode on the one side. I'll check that too to see if I posted the wrong link... But, I suppose it doesn't really matter as I think you are agreeing here - there's no need for a darlington anyway.

I got my 12v PSU and test relays yesterday. Right now I have one of my most power demanding systems running on it and it seem good so far. I just wired it direct on the NC pair just to have it pulling the power through it. Other than it being maybe a couple of degrees Fahrenheit warmer the the others beside it (not connected to anything yet) it seems good. The PSU I got for the relays is a Mean Well 12v/1.67A unit DIN rail mount style. I'll have to find the details on the relays - yes they are cheap ones - for the price - I will be their tester. I might even get them to cool down to no noticeable temp diff as I think the wire I used to connect it is a little smaller than it could be. I'm limited on power cords at the moment and didn't to want cut up its current heavy duty cord for testing. The wires feeding it are also just slightly warmer than ambient, thus my suspicion of the wiring. If this all goes well I'll redo all the wiring with heavier guage solid wire.

Anyway - thank you again for you very thoughtful responses.
"When money ceases to be the tool by which men deal with one another, then men become the tools of men. Blood, whips and guns–or dollars. Take your choice–there is no other..."
- Ayn Rand - Atlas Shrugged

Return to “Automation, sensing and robotics”