Relay diode suppression for Raspberry Pi - single diode not enough, what next?

Baker Steve

Joined Feb 21, 2016
29
See post #12!
Though for *really* big loads, I’d use the triac to switch a contactor.
I’ve switched 100kW using that method.
The triac would get a tad warm - dissipating 1 Watt for each amp of load current.
Sorry - didn't read your post 12 right to the end. But surely a contactor would land the thread starter back with EMF issues from arcing?
 

Ian0

Joined Aug 7, 2020
13,158
Sorry - didn't read your post 12 right to the end. But surely a contactor would land the thread starter back with EMF issues from arcing?
If it did, then they wouldn't be on the same supply as his logic. But switching a motor with a triac won't be a lot better - the triac switches off when the current reaches zero. With an inductive load the voltage will be nowhere near zero when it switches off. No arcing, but a lot of dV/dt. From practical experience, I have switched 100kVA with a triac-driven contactor without a problem.
A solid-state relay would do the job as well. Looks like an opto-isolator from the point of view of the microcontroller. Not the cheapest, but gets the job done.
 

slackguy

Joined Feb 11, 2016
76
"spikes from coils"? i'm doubting your relay should ever contain voltage from the power side or even 2nd relay 1500w: the two are parts inside a relay physically separate, obviously. so i'm "a doubter on many of the previous posts". and the premise of a transistor base control ampifying (powering a relay) is that the base is un-effected by the throughput, so i have doubts "feedback" there too.

i'm unsure what this "pull down" terminology means or why you added a physical S1. i would use only the input and output voltage and amperage the GPIO documents as safe for 100% duty cycle, i would not just jam in resistors or lack thereof.

i'm not to familiar with spike protection, though i know capacitors are sometimes used.

i'm not convinced you didn't damage your gpio or 3.3 mosfet (or if it is a programmable mosfet) or both by pulling more volts or amps through the programmable transistor base than your gpio allows. but your just plugging resistors here and there and not giving exact voltage and amperage expectations?

3.3 mosfet seems to be rated "for conditions much harsher than the gpio"

the IDEC says 6 amp - i don't see where it says the power to throw the IDEC RELAY or if it has a spring (do you have to maintain the 24V at unknown current for this to stay on? or you have a two-way setup - one zap to throw it on, one zap that allows it to fall back to OFF). obiously we seek a relay with near zero current maintenance. but is that what this beastie is? then there is the second "power relay" and it probably may require continual full current to stay open (or may not, but what is the maintenance current to keep that big switch open?)

i haven't crunched all the numbers, though... let's see your Pi compute says don't exceed 18 mA for 3.3V, the MOSFET uses (data sheet says .4 mA? enhanced mode: conducts some when input is OFF - and increasingly conducts as voltage runs higher (in your case you go from 0V to 3.3V) - and therefore your 1st relay must accept some voltage normally but be triggered when raised by the second voltage (to me it is yet far from clear if that is how the 1st relay IDEC works). if the MOSFET is programmable: i have no help there - you bought it - read up - if it is then it might conducuct or not conduct some voltages or currents due to thresholds or even curves (ie, automatically shutting off if above or below for a certain period of time). Now for the IDEC: the DOC you cited by giving the URL doesn't contain ANY information upon the inputs to it and the responses to the inputs: so i have zero idea how you would be using a MOSFET as a switch to power it (correctly). all i know is for a mosfet to act as a switch it needs to be in a little circuit itself (not just plugged in between destination and source as your rough diagram shows). The IDEC is normally open (no current), so your MOSFET going from 0v must be inactive and 3.3V (+-? see below) must activate it. Again: the IDEC doc you showed us does not show the "how much power it eats for how long" and if it maintains itself and what if any triggers there are. Finally your power relay looks like a power hog that requires energization at all times to stay "closed" (conducting)

gpio pullup -ardiuno -raspberry tells me pullup means resistor connected when Vin is floating: as far as i can determine that means "it's a resistor". i'm seeing something like 45 GPIO pins and some are hi some are lo - i see nothing saying which are (up to, maxiumum) +3.3V or -3.3V or if one of the two is forbidden on I or O. i'd like to know at least which is + which is - and range and can't see how the term "pulldown" has added anything to the documentation.

sorry if that didn't help

It seems to me your GPIO output should be (rather can be) a constant +-3.3v, you could amplify that on a transitor base "safely indeed" to power a 24v relay (perhaps having to power that coil to keep it on), which then powers the bigger relay. If it were much simpler it'd be better?

Now as far as detecting a single GPIO trigger as an "on/off" flip flop: you've given no time window of your goal or any of the parts I hope that's not what your attempting, since none of the parts are so accurately designed your circuit would need to compensate and lacks of curves predicted to make that happen "reliably". If you want a flip flip (push button scr), then there's plenty of plans for those on the internet that are sloppy (meaning, a human can activate them by a switch which is a pretty sloppy signal)
 
Last edited:

slackguy

Joined Feb 11, 2016
76
if your attaching a PC part to a relay - and if you value it - you should own a cheap optical coupler so you fry anything but your gpio
 

slackguy

Joined Feb 11, 2016
76
I see now the IDEC has very specific time windows. But you chart doesn't show your input voltage (the IDEC says 4.5V is minimum, your chart says 3.3V). The chart says you drop out at 1.5V - so if your MOSFET provides something in that range for 0V (remembering it is enhanced mode), you'll have trouble.

but input current to IDEC is 10mA±10%(±6VDC) - this is wildly different from what could be the output of your MOSFET (up the 6A), the two components are "very mismatched" per say unless used _very_ carefully.

the operating time of the IDEC is ~ 100 us, the rise and fall time of the MOSFET is ~ 1/10 of that so more than one pulse would always be required, as far as digital windows go.

So that made me think: what? drive a motor with that??

I am at a loss how, given what I've seen (the diagram) how this would be expected to drive a motor requiring something like a sine wave input. Is the GPIO programmed to produced the frequency of the motor required? how would it know (feedback)?

So your telling me the GPIO input would have to have feedback from the motor position, the "3 ns" gpio would have to step it's output pulses so that a "10us MOSFET" could tell a "100 us" relay that powers a "30 ms" power relay with a continually good signal?

But i'm confused because your talking about "pulldown switches being thrown", but others say you are driving a motor by sine wave - the two don't compute (it's unlikely to me your are saying a single motor pulse was missed by saying pulldown was thrown). So i have two stories about what the purpose of this device is?

I think it's great it even worked the first time powering a motor! Is it efficient? Can it harm the motor being served?

I think you could be more specific about the inputs and outputs unless your fishing for someone who's built one before to clue you in on some design trick.

I mean - it's totally unclear if you are measuing if it's raining as to whether to turn on or off a washer, or if your driving the washer motor with pulses.
 

slackguy

Joined Feb 11, 2016
76
I have to say again: the documentation you specified shows 45 pin GPIO - no clear input or output (i can look at), and I have to question again: programmed I/O is certainly not designed to allow it's output to "trigger" physical or other switches outside the package on the input side - i'm pretty darn sure. but you say it did (now that's as far as I can read your lingo) (in other words, what you said should be impossible, with the graph you have, and your explination)
 

slackguy

Joined Feb 11, 2016
76
finally, with this in mind (if this is what your up to, but as i said just above, you haven't said so)

https://simple-circuit.com/arduino-dc-motor-control-bridge-rectifier-thyristors/ (requires a motor controller i think - but the website asks if "i agree" and really: i don't)

this, i think, makes it clear that you need a whole schematic and haven't posted what schematic you are using and that you have not designed one yourself from scratch

https://www.electronicshub.org/controlling-a-dc-motor-with-raspberry-pi/#Circuit_Diagram

(this one actually requires : L293D Motor Driver IC or Module, meaning as i suspected, controlling a motor using the Pi and a python script is virtually impossible. you might be controlling power or direction if the rest is taken care of for you)

  • DC Motor are found everywhere: robots, drones, RC Cars, etc. By Controlling a DC Motor with Raspberry Pi, we can develop robots using Raspberry Pi. :0

Now - these diagrams with python code are made by non-amateurs to foster use of their products - so i'm relatively sure you are not designing this.

THAT BEING SO, how are you asking what resistor or diode to quash while you have no diagram URL ? (no motor controller, no python script, people talking about driving DC motors in response). I can't see how anyone else even responded to the initial question, personally. You have no DC motor controller chip. And unless the DC motor has an integrated controller?

I must assume we are then back to turning a relay on or off (which is what i first argued) - where it is unknown why you are using a higher cost $10 "very specific" component (IDEC) that isn't conducive to easy switching via mosfet (for reasons stated - you need the mosfet in a circuit to cause it to act as a switch or match the state curves otherwise so the IDEC doesn't get confused).

Why not use a single transistor from the GPIO (possibly a second transistor off that) if all you want to do is use cheap parts to throw an on-off $40 relay requiring a constant amperage (<< 1A) to stay closed?

I can't see using industry "programmable" components (ie, MOSFET) for a simple home project. There are too many curves and uses (for reasons), because they are designed to be widely applicable to industry use. You might as well go from scratch if you just want an "on/off".
 

Ian0

Joined Aug 7, 2020
13,158
Both are good circuits, mine probably comes from the days of the 8051 which had pullups that couldn't be switched off, yours is nicely symmetrical but needs the pullups to be switched off.
A TVS is just a big zener! It would need a 3.3V device to protect the input and that's only available if it's called a zener e.g. 1N5333, which is rated 180W if it's rated the same way as a TVS. Nanok66 doesn't tell us the length of wire to his switches so we can't guess whether we would need such heavy duty input protection.

As Raspberry Pi inputs are not 5V tolerant it probably has clamp diodes to both supplies which might not need any external help apart from a bit of series resistance. I deal with microcontrollers with 5V tolerant inputs, and I don't trust them to deal with a positive-going spike because of the lack of clamp-diode to V+.
 

Ian0

Joined Aug 7, 2020
13,158
"spikes from coils"? i'm doubting your relay should ever contain voltage from the power side or even 2nd relay 1500w: the two are parts inside a relay physically separate, obviously. so i'm "a doubter on many of the previous posts". and the premise of a transistor base control ampifying (powering a relay) is that the base is un-effected by the throughput, so i have doubts "feedback" there too.
Not from the output side (presumably that's what you mean by "power side", the interference comes from the energy stored in the coil of the relay.
i'm unsure what this "pull down" terminology means or why you added a physical S1. i would use only the input and output voltage and amperage the GPIO documents as safe for 100% duty cycle, i would not just jam in resistors or lack thereof.
A pull down resistor is used when a switch is connected to a logic input, to ensure that the logic input reads zero when the switch is open.
A pull up resistor is used when a switch is connected to a logic input, to ensure that the logic input reads one when the switch is open.
Without a switch, how is the customer going to control the apparatus? Telepathy?
i'm not to familiar with spike protection, though i know capacitors are sometimes used.
Really?
i'm not convinced you didn't damage your gpio or 3.3 mosfet (or if it is a programmable mosfet) or both by pulling more volts or amps through the programmable transistor base than your gpio allows. but your just plugging resistors here and there and not giving exact voltage and amperage expectations?
A programmable MOSFET?
The MOSFET in question will withstand +/- 12V on the gate. The GPIO won't damage it.
If you can put an "exact" value on the amount of interference, then you can calculate an exact value for the components to suppress it!
3.3 mosfet seems to be rated "for conditions much harsher than the gpio"
Yes - it's rated for the relay it is driving
the IDEC says 6 amp - i don't see where it says the power to throw the IDEC RELAY or if it has a spring (do you have to maintain the 24V at unknown current for this to stay on?
It's in the datasheet. Coil resistance is 2270 ohms. Pickup voltage is 19.6V, dropout voltage is 5V.
That means >10mA to close the contacts, <2.2mA to open the contacts.
or you have a two-way setup - one zap to throw it on, one zap that allows it to fall back to OFF). obiously we seek a relay with near zero current maintenance. but is that what this beastie is?
No - it's not a latching relay
then there is the second "power relay" and it probably may require continual full current to stay open (or may not, but what is the maintenance current to keep that big switch open?)
In the datasheet again. 290 ohms coil resistance. On at >85% of rated coil voltage (20.4V) and off at <10% (2.4V) but that's the voltage that it is guaranteed to drop out at. Could drop out at higher voltages
i haven't crunched all the numbers, though... let's see your Pi compute says don't exceed 18 mA for 3.3V, the MOSFET uses (data sheet says .4 mA? enhanced mode: conducts some when input is OFF
No, less than 1uA at zero gate voltage according to the datasheet.
- and increasingly conducts as voltage runs higher (in your case you go from 0V to 3.3V) - and therefore your 1st relay must accept some voltage normally but be triggered when raised by the second voltage (to me it is yet far from clear if that is how the 1st relay IDEC works).
Like every other relay in the world - supply the coil with the rated coil voltage and the contacts close!
if the MOSFET is programmable: i have no help there - you bought it - read up - if it is then it might conducuct or not conduct some voltages or currents due to thresholds or even curves (ie, automatically shutting off if above or below for a certain period of time).
It isn't - MOSFETs aren't programmable. On at >2.5V gate-to-source (the gate threshold voltage from the datasheet). Off at <2.5V gate-to-source. So definitely on at 3.3V and definitely off at 0V. No problems there.
Now for the IDEC: the DOC you cited by giving the URL doesn't contain ANY information upon the inputs to it and the responses to the inputs: so i have zero idea how you would be using a MOSFET as a switch to power it (correctly). all i know is for a mosfet to act as a switch it needs to be in a little circuit itself (not just plugged in between destination and source as your rough diagram shows).
Rough diagram is absolutely correct. Exactly how one uses a MOSFET to switch a relay. Just need the reverse diode across the coil.
The IDEC is normally open (no current), so your MOSFET going from 0v must be inactive and 3.3V (+-? see below) must activate it. Again: the IDEC doc you showed us does not show the "how much power it eats for how long" and if it maintains itself and what if any triggers there are.
24V divided by the coil resistance =10mA.
Finally your power relay looks like a power hog that requires energization at all times to stay "closed" (conducting)
Yes. Not a latching relay.
Current = 24V divided by the coil resistance = 82mA.
Power = 24V squared divided by coil resistance = 2 Watts
gpio pullup -ardiuno -raspberry tells me pullup means resistor connected when Vin is floating: as far as i can determine that means "it's a resistor". i'm seeing something like 45 GPIO pins and some are hi some are lo - i see nothing saying which are (up to, maxiumum) +3.3V or -3.3V or if one of the two is forbidden on I or O. i'd like to know at least which is + which is - and range and can't see how the term "pulldown" has added anything to the documentation.
See Raspberry Pi GPIO spec
https://www.raspberrypi.org/documentation/hardware/raspberrypi/gpio/README.md
it's on the last line
It seems to me your GPIO output should be (rather can be) a constant +-3.3v, you could amplify that on a transitor base "safely indeed" to power a 24v relay (perhaps having to power that coil to keep it on), which then powers the bigger relay. If it were much simpler it'd be better?
As previously mentioned by myself and several others - triac, triac+contactor, MOSFET driving single large relay, solid state relay etc.
 

Ian0

Joined Aug 7, 2020
13,158
I have to say again: the documentation you specified shows 45 pin GPIO - no clear input or output (i can look at), and I have to question again: programmed I/O is certainly not designed to allow it's output to "trigger" physical or other switches outside the package on the input side - i'm pretty darn sure. but you say it did (now that's as far as I can read your lingo) (in other words, what you said should be impossible, with the graph you have, and your explination)
Most GPIO pins can be programmed as either input or output.
What are they for if not driving external circuits?
 

Ian0

Joined Aug 7, 2020
13,158
finally, with this in mind (if this is what your up to, but as i said just above, you haven't said so)

https://simple-circuit.com/arduino-dc-motor-control-bridge-rectifier-thyristors/ (requires a motor controller i think - but the website asks if "i agree" and really: i don't)
this, i think, makes it clear that you need a whole schematic and haven't posted what schematic you are using and that you have not designed one yourself from scratch

https://www.electronicshub.org/controlling-a-dc-motor-with-raspberry-pi/#Circuit_Diagram

(this one actually requires : L293D Motor Driver IC or Module, meaning as i suspected, controlling a motor using the Pi and a python script is virtually impossible. you might be controlling power or direction if the rest is taken care of for you)

  • DC Motor are found everywhere: robots, drones, RC Cars, etc. By Controlling a DC Motor with Raspberry Pi, we can develop robots using Raspberry Pi. :0

Now - these diagrams with python code are made by non-amateurs to foster use of their products - so i'm relatively sure you are not designing this.

THAT BEING SO, how are you asking what resistor or diode to quash while you have no diagram URL ? (no motor controller, no python script, people talking about driving DC motors in response). I can't see how anyone else even responded to the initial question, personally. You have no DC motor controller chip. And unless the DC motor has an integrated controller?
Nanok66 has an AC motor, presumably an induction motor, which requires no more than being switched on or off
I must assume we are then back to turning a relay on or off (which is what i first argued) - where it is unknown why you are using a higher cost $10 "very specific" component (IDEC) that isn't conducive to easy switching via mosfet (for reasons stated - you need the mosfet in a circuit to cause it to act as a switch or match the state curves otherwise so the IDEC doesn't get confused).
Confused? How can a coil of wire and a moving contact get confused?
Why not use a single transistor from the GPIO (possibly a second transistor off that) if all you want to do is use cheap parts to throw an on-off $40 relay requiring a constant amperage (<< 1A) to stay closed?

I can't see using industry "programmable" components (ie, MOSFET) for a simple home project. There are too many curves and uses (for reasons), because they are designed to be widely applicable to industry use. You might as well go from scratch if you just want an "on/off".
I somehow doubt that a keg washer is a "home project", unless he is taking a home-brew hobby very seriously indeed!
And what's all this nonsense about a simple little MOSFET being a "programmable industrial component". The curves are trivial to intepret.
 
If the gate of a MOSFET does not include a pull down resistor, the leakage current can turn it on if the gate is left open. The pull down just has to be sized to have a path for the leakage current to go. So, 10K to 100K ought to work without any calculations.
 

Thread Starter

nanok66

Joined Jul 14, 2016
75
Damn you guys are going to town! Thanks everyone... it might take me a while to process all the info here. Also there are so many answers I am almost more confused which way to go lol

Maybe I should simply ask, how should I switch my 220V devices (1HP motor, 6kW heating element) starting with the 3.3V GPIO of the Pi Compute?

Is my logic level MOSFET still ok to start this circuit? It's already on a PCB that I made specifically for this machine...


@Ian0 yes diode is the exact one from automationdirect.com 24VDC transorb module. That's why I chose it. But ok I can use a normal diode. And yeah I can probably just skip the first IDEC relay. I wasn't sure if the MOSFET would be able to handle the 4W consumption of the power relay coil. The 1st relay consumption is only .25W. Also thanks for offering the opto-triac circuit idea. I am open to redoing the circuit, down to research it but can you recommend any components (or even just a good article) I should look at to start? Hopefully I can keep the MOSFET cuz it's already on a custom PCB that the Pi connects to. I have both 24VDC coil and 110VAC coil contactors at my disposal for this project.. I just picked the 24VDC ones arbitrarily. Overall what I am asking is what should go between the MOSFET and the contactor?

@gernot Wow you modeled my circuit! I do have LTspice installed but honestly I've barely used the program. Are you saying that if I modified my circuit to be closer to your model, it should work alright? Also whoa your other post (#20) is helpful too. Yeah I can software debounce my input switch. I'm using python event detect for the GPIO and I could write in a test to make sure a "real button press" is > 10ms or something like that.

@Baker Steve yeah I'm down to partially redo my circuit. But from studying similar machines, the engineers usually use a contactor to switch on the 220VAC. And I'd still prefer to use my logic level MOSFET since it's already in a custom PCB. I'm not sure the MOSFET is beefy enough to directly drive my contactor relay coil (4W consumption and it stays on for long time) so I thought there should be something in between..

@slackguy Hey thanks for the response. Long response tho so not sure where to start with your advice, here's the actual IDEC datasheet to start. Also the GPIO control.. there's no output trigger, the output from the Pi GPIO is either 0V or 3.3V steady to turn the MOSFET on/off, which in turn keeps the relays on. The motor is not digital it's a 1HP 220V motor switched on by the contactor or "power relay" as I called it. My python program turns the GPIO's on/off as needed to operate my motor and 6kW heating element. The circuit works fine except for these mysterious spikes. Maybe you confused the trigger with the false triggers I am getting on totally different input buttons (these buttons make the software start or cancel the machines python program). I am totally down to use some optocouplers in this circuit, just not exactly sure where to start yet.

Anyway, this product is going to be very serious as in I am already using it and have washed thousands of kegs for my brewery (Vision Quest - Boulder, CO). Also I have already sold my first machine to a friend. I have about a month before I deliver the new machine to him so I am definitely looking for the most professional solution to this as possible.

To recap, all the keg washers I have studied use contactors to run the 220V devices (motor and heating element). I am certainly stuck using the Pi (I know pretty much all other machines like this use PLC's but I think the Pi is plenty capable and hopefully stable enough to replace the PLC. Plus something has to run the touchscreen so why not let the Pi run touchsceen and be the PLC too). I would preferentially like to keep the MOSFET in the design but if y'all think the most pro solution would not include it then I'm all ears on what to use instead. Cheers.
 

Ian0

Joined Aug 7, 2020
13,158
If the gate of a MOSFET does not include a pull down resistor, the leakage current can turn it on if the gate is left open. The pull down just has to be sized to have a path for the leakage current to go. So, 10K to 100K ought to work without any calculations.
Good point, but not without a trap for the unwary.
When the raspberry pi is running, the pulldown is superfluous, as the GPIO has a very good pulldown.
The problem occurs during those few moments when it is all starting up, and the GPIO is in its default state, configured as an input, probably with the pull-ups turned on.
Choose a pull down of about 10% of the value of the pull-ups (about 2.2k) to make sure that the MOSFET is definitely off.
A pulldown of the same value of the pull-up (50k) would bias the MOSFET into its linear region, so You wouldn’t know if it would be on or off, and if it were driving a heavier load would make it dissipate lots of power and blow up.
 

Ian0

Joined Aug 7, 2020
13,158
To recap, all the keg washers I have studied use contactors to run the 220V devices (motor and heating element). I am certainly stuck using the Pi (I know pretty much all other machines like this use PLC's but I think the Pi is plenty capable and hopefully stable enough to replace the PLC. Plus something has to run the touchscreen so why not let the Pi run touchsceen and be the PLC too). I would preferentially like to keep the MOSFET in the design but if y'all think the most pro solution would not include it then I'm all ears on what to use instead. Cheers.
For 6kW a triac or solid-state relay on its own would dissipate 30W which would need a big heat sink, so I would go for an opto triac (FODM3063) connected between GPIO and 3.3V,through about 180 ohms; driving a small triac Z0107MN (100ohms 1W between onto-triac and main triac gate) driving a contactor, with a snubber (47 ohms in series with 47nF class-X) across the coil.
That keeps ALL the switching noise out of the low voltage supplies, AND ensures that you don’t get a brief switch-on during power-up.
Switching the heater with a contactor is quite benign in terms of interference, and it gives you the chance to put some physical distance between contactor and control circuit.
 
Top