Page 1 of 1

HELP with relay and "spikes"

Posted: Wed Dec 16, 2015 8:32 am
by Massi
Hello all,
this is one of those problem that you can clearly see but you have no idea how to debug :)

So, the situation.

I have one of these relay board
http://www.dx.com/p/arduino-2-channel-r ... nEfDErhDIU

and, until yesterday, i'd say that "it works"

Where "it works" means that i can easily control something through it (the load isn't relevant for this, btw the specific is a 12v solenoid valve)

It is connected, as output, to a MCP23017 chip. The chip also controls a HD44780 display and has a couple of input pins,

Both the MCP and the relay are powered by a dedicated power supply (not the PI), that is this
http://www.dx.com/p/3-3v-5v-power-suppl ... nEf7krhDIU

(common ground with raspberry, ok)

Now, the problem:

When the relay is toggled ON, no problem at all. The valve starts, the display works, everything is ok.
BUT
When the relay is toggled OFF, something happens.
The valve stops with no problem, BUT:
- sometimes i can see a fake interrupt on input switches
- sometimes the display shows "corrupt" chars

And i underline SOMETIMES, because sometimes it works all as expected :)

So, what can be the source of the problem?

The easiest idea i can have is a spike on power (5V) that flows to the 3,3V line on the MCP. I expected the power source to be stabilized, but maybe it is not..
But this is because i like to think that no spike is returned to the mcp by the relay! is this the case? ame is a master to understand relay boards looking at them on dx :)

Last but not least, can it be a "interference" problem? (very very hard, for me)

And, finally, can i help something adding some capacitors here and there? and, if yes, what capacity have i to use? for data lines? for power lines?

Thanks all :)

Re: HELP with relay and "spikes"

Posted: Wed Dec 16, 2015 1:01 pm
by Massi
so, after some reading, i've understood that spikes with mechanical relays are always present.

Well, if i got it right the simpliest thing i can do is.. trash them and get some solid state relays :)
(Edit: like this? http://www.dx.com/p/2-channel-5v-ssr-so ... nFhZ0rhDIU )

But, just for personal curiosity, is a TVS diode the solution? and if yes, how should i size it?
More then this, i think that you can have spikes only on the primary circuit and not on load circuit, am i right?
because in my case the same 12V power source is powering (through the linked voltage converter) the "system" circuit, and on the other side it is powering (through the relay) the coil.

Please help :)

Re: HELP with relay and "spikes"

Posted: Wed Dec 16, 2015 1:11 pm
by drgeoff
You always get a spike when current through a coil (an inductor) is suddenly turned off.

Yes, try a diode across the relay coil. Just about any diode like a 1N4001 will do.

Re: HELP with relay and "spikes"

Posted: Wed Dec 16, 2015 1:16 pm
by Massi
drgeoff wrote:You always get a spike when current through a coil (an inductor) is suddenly turned off.

Yes, try a diode across the relay coil. Just about any diode like a 1N4001 will do.
even the valve is an inductor (it's a solenoid..), have i to take care also of this?

for the primary circuit, is a 1n5908 good?

the 1N4001 is a common diode, not a TVS, am i wrong? is it good anyway?

Re: HELP with relay and "spikes"

Posted: Wed Dec 16, 2015 1:56 pm
by ame
drgeoff wrote:You always get a spike when current through a coil (an inductor) is suddenly turned off.

Yes, try a diode across the relay coil. Just about any diode like a 1N4001 will do.
That board has diodes fitted across the coils already.

Re: HELP with relay and "spikes"

Posted: Wed Dec 16, 2015 2:01 pm
by Massi
ame wrote:
drgeoff wrote:You always get a spike when current through a coil (an inductor) is suddenly turned off.

Yes, try a diode across the relay coil. Just about any diode like a 1N4001 will do.
That board has diodes fitted across the coils already.
so what am i facing?

Re: HELP with relay and "spikes"

Posted: Wed Dec 16, 2015 2:11 pm
by ame
Massi wrote:
ame wrote:
drgeoff wrote:You always get a spike when current through a coil (an inductor) is suddenly turned off.

Yes, try a diode across the relay coil. Just about any diode like a 1N4001 will do.
That board has diodes fitted across the coils already.
so what am i facing?
Modify your software to ignore the false interrupts, and to refresh the display to get rid of corrupt characters.

You might get some relief if you add some capacitors at various places in your system. A couple of 100uF for the main power supply inputs, and some 0.1uF for the smaller devices. Also, watch out for long wires which can act as antennas, or thin wires which can starve devices of current. Google for "decoupling capacitors" or "bypass capacitors" for some ideas.

Re: HELP with relay and "spikes"

Posted: Wed Dec 16, 2015 2:15 pm
by Massi
is solid state a definitive solution?

Edit to add: can the problem be sourced by the load circuit?

Re: HELP with relay and "spikes"

Posted: Wed Dec 16, 2015 3:50 pm
by Tage
Massi wrote:is solid state a definitive solution?

Edit to add: can the problem be sourced by the load circuit?
My guess is that the problem is caused by arcing between the relay contacts that are opening. When you have an inductive load such as a solenoid and the relay contacts open, the inductive current cannot stop immediately, so an arc is formed between the opening contacts and the energy stored in the inductive load burns off in the arc. there will also be a voltage spike across the contacts.

the solution is to add a small capacitor across the relay contacts. this will redcue the electical noise and the arcing. the capacitor could be a ceramic or plastic capacitor 0.01uF to 1uF. the load current mostly goes into charging this capacitor and the arc is suppressed.
the voltage spike can be controlled by adding a diode across the solenoid coil. the diode provides a path for the stored energy in the coil to dissipate.

a solid state relay is not the solution. a MOSFET transistor is better choice, it will not arc. but you will need the diode across the solenoid load. or a diode from the drain of the MOSFET to the +12V load supply, so the voltage spike at turn off does not kill the transistor.

Re: HELP with relay and "spikes"

Posted: Wed Dec 16, 2015 4:05 pm
by Massi
Tage wrote:the solution is to add a small capacitor across the relay contacts. this will redcue the electical noise and the arcing. the capacitor could be a ceramic or plastic capacitor 0.01uF to 1uF. the load current mostly goes into charging this capacitor and the arc is suppressed.
the voltage spike can be controlled by adding a diode across the solenoid coil. the diode provides a path for the stored energy in the coil to dissipate.
thank you so much!
let me make another question :) a capacitor across the contact OR a diode across the solenoid coil or a capacitor across the contact AND a diode across the solenoid coil? :)
Indeed, i excluded the load from the problem but probably it is the source of all.. this evening i'll try the relay without the load and see what happens..
i should have some capacitors at home, but not diodes so can i try with only the capacitor?

i got one of these http://www.dx.com/p/hongyang-m-300-30-v ... nGLY0rhDIU so a 104 should be ok, isn't it?

Even today i learnt something new :)

Re: HELP with relay and "spikes"

Posted: Thu Dec 17, 2015 2:27 am
by Tage
Massi wrote:
Tage wrote:the solution is to add a small capacitor across the relay contacts. this will redcue the electical noise and the arcing. the capacitor could be a ceramic or plastic capacitor 0.01uF to 1uF. the load current mostly goes into charging this capacitor and the arc is suppressed.
the voltage spike can be controlled by adding a diode across the solenoid coil. the diode provides a path for the stored energy in the coil to dissipate.
thank you so much!
let me make another question :) a capacitor across the contact OR a diode across the solenoid coil or a capacitor across the contact AND a diode across the solenoid coil? :)
Indeed, i excluded the load from the problem but probably it is the source of all.. this evening i'll try the relay without the load and see what happens..
i should have some capacitors at home, but not diodes so can i try with only the capacitor?

i got one of these http://www.dx.com/p/hongyang-m-300-30-v ... nGLY0rhDIU so a 104 should be ok, isn't it?

Even today i learnt something new :)
the ceramic capacitors you have will work just fine.
the capacitor placed across the relay contacts will decrease the electrical noise that the arcing causes. the arc is like a high power radio transmitter, and any wires connected to the relay will act as antennas. this is probably why you have trouble with noise pickup on some pins of the micro controller. noise is coupling between the arcing relay and the inputs of the micro. you reduce the volume of the noise by putting a capacitor across the relay contacts. you could also put a small capacitor from the GPIO input that you have a problem with, to GND. this will filter out some noise and probably get rid of the noise problem.

the diode is not really needed when you have a relay that controls your inductive load, but if you were using a transistor of some kind instead of a relay, then you need the diode to avoid that the voltage spike damages the transistor by overvoltage.

Re: HELP with relay and "spikes"

Posted: Thu Dec 17, 2015 7:18 am
by ame
What load is connected to the relay?

If you disconnect the load and operate the relay do you still see the problem?

Re: HELP with relay and "spikes"

Posted: Thu Dec 17, 2015 8:36 am
by Massi
ame wrote:What load is connected to the relay?

If you disconnect the load and operate the relay do you still see the problem?
the load is a 12V solenoid valve.
as i said above, i was wrong excluding the load from the problem, but i've not yet tested the circuit without the load (it's my plant watering system and it's so cold in the evening here :))

Re: HELP with relay and "spikes"

Posted: Sat Dec 19, 2015 10:17 am
by Massi
a single 104 capacitor didn't solve
but a couple of 104 seems to have done the magic :) thanks a lot to all of you..

Re: HELP with relay and "spikes"

Posted: Tue Mar 07, 2017 5:26 am
by liorillusion
I have the same pronlblem with load im getting input. Without all is ok.how you solve it?

Re: HELP with relay and "spikes"

Posted: Tue Apr 30, 2019 9:38 pm
by snowbord
Just a heads up that a 10uF cap across the COM / NO terminals of the relay board fixed this otherwise epic problem for me. 100nF didn't, 2x100nF didn't, neither did 1uF. I too am using a 12V (2A) solenoid.