Intermittent problem with relay board project...

I’m having some difficulty with my project. I’m using an UNO board with a 4-relay opto-isolated shield to reverse the current for a model train system so the train will auto-reverse when particular switches are activated. More simply put I have an adjustable 0-17V DC transformer feeding power to a DC motor (through the model railroad tracks). The relays shut off and/or reverse the current when needed.

The project runs almost flawlessly. The only problem I have is that when there is a load going through the relays I get intermittent phantom button presses and resets. The phantom button presses don’t necessarily happen when the relay’s click on or off, it can happen at any time while a load is present through the relay’s. The higher the voltage applied to the motor from the transformer through the relays, the more frequent the glitching. At close to 17 volts the UNO will constantly and instantly reset the moment one of the relays click.

I provided a (crude) diagram of my circuit. The relay board and UNO sit inside of a 4” x 8” project box, the transformer is mounted 12” away from the project box and the track rails that provide power to the train’s DC motor is roughly 23’ in length and the power wires from the relays are soldered to the track in the middle of the line (12’ on each side) .

Some side notes:

The code, switches, and relays work perfectly as long as no power is going through the relay contacts.

I tried powering the relay board through the UNO and also with an independent 5v 1amp switching DC power supply (though JD-VCC, ground connected to UNO, jumper removed). This made no difference. Also, if relay 5V power’s ground was not also connected to the UNO’s ground then the relay board did not function. See wiring diagram.

I tried a 9v DC 1amp switching power supply and also USB port power for the UNO but this made no difference.
From what I read this is a somewhat common relay issue and someone mentioned something called a “snubber”. Would this apply to this situation and if so how would I connect one (or more) in this setup where multiple relays shut off and reverse variable-voltage DC current? Any other suggestions as to how to correct this problem?
Thanks!

  1. Remove the ground link between relay board and Arduino.
    With that Arduino ground you don't have opto isolation.

  2. Must have back-emf diodes across the motor terminals (tracks).
    For reversing motors you can use a diode bridge with the two AC terminals connected to the motor and the + and - to the motor power supply.
    A 100n ceramic cap across the motor terminals might also be needed.
    Leo..

Wawa:

  1. Remove the ground link between relay board and Arduino.
    With that Arduino ground you don’t have opto isolation.

When I disconnect the arduino’s ground from the relay board so only the independent 5V relay supply (+ connected to JD-VCC) ground is connected, then the relay board does not function. When I connect the independent 5V relay supply’s ground to the arduino’s ground, then it functions. I’ve read this same suggestion elsewhere in the forum but could never get that configuration to work properly.

Wawa:
2) Must have back-emf diodes across the motor terminals (tracks).
For reversing motors you can use a diode bridge with the two AC terminals connected to the motor and the + and - to the motor power supply.
A 100n ceramic cap across the motor terminals might also be needed.
Leo…

Are you referring to a full-wave/bridge rectifier? If this is what you are referring to can you please take a look at the modified diagram I attached to this message and let me know if this setup is correct? Lastly, assuming it is correct, and pardon my ignorance, but on a bridge rectifier the AC terminals and +/- terminals are interchangeable as long as (per the diagram) terminals A-C and B-D are paired correctly, yes?

P.S. apologies for the poor quality diagram. For some reason my modified diagram “failed security check” and wouldn’t upload. Therefore I had to take a phone picture of my screen and upload it. If anyone knows why this happened please inform.

Thank you!

If you power a common opto-isolated relay board externally on JD-VCC/GND,
with the JD-VCC jumper removed, then Arduino ground is not needed.
Post a link to that relay board.

Correct about the bridge rectifier.
AC terminals can be swapped, but +/- must go to +/- of the supply (as per your diagram).
Any motor voltage now can't go outside the supply limits more than a diode threshold (0.7volt).

I think some image editors add tags to the file that the forum doesn't like.
Leo..

Wawa:
Post a link to that relay board.

This is identical to the board I have except the numbers on the actual relay’s are different. I attached a photo of the exact (“jqc-3ff-s-z”) relay’s that are on my board.

http://wiki.sunfounder.cc/index.php?title=4_Channel_5V_Relay_Module

Makes no sense.
The circuit diagram on that link shows that the opto LEDs are driven between VCC and IN,
just like the 'other' common opto-isolated boards.
Ground to the Arduino should not be needed.
Leo..

The relay power side appears to to totally isolated as it should be.

The power for the relays is shown as the 5V 1A t
This should be completely isolated from the UNO board

The dotted line is connected to a jumper pin and 'should not' be connected to the signal ground for purposed of isolation

however, the signal lines should be grounded to the UNO is some way to complete the circuit.

if there is any power change, and the voltage drops on the board, then that would reset the board, that would be bad, means power is being drawn on some wires that it should not be.

I would look at adding a cap on the power of the UNO to help with that.

as for the motor side of things, the fact you reverse the motor and the fact that the power supply is completely separate should remove that from the equation.

The only need for diodes is on the relay coil, not the motor coils.
and then, if you want to add diodes for peace of mind, they would go on the power supply side AKA COMM of the relay, from ground to Vcc. any spike on one motor would be adsorbed by other motors so there should not really be to large of a back EMF and it should not have any effect on the power or signals of the UNO in any case.

2 things to try. The first is pretty simple, the other a little complicated.

  1. In the setup() routine of your sketch, try setting all the unused pins on the Arduino to INPUT_PULLUP so you have no floating pins.

  2. more complex, but you put some protection on the Uno lines going to your relays. See this post https://forum.arduino.cc/index.php?topic=310386.msg2153898#msg2153898
    It seems there it was an issue of needing to block EMI on the input line.

There are several examples on the digikey page here: https://www.digikey.com/en/articles/techzone/2012/apr/protecting-inputs-in-digital-electronics

Perhaps someone with a bit more knowledge than me can indicate whether a particular one of those examples will be more or less relevant in your application.

Also, just to summarize the previous posts, I believe folks are saying to ensure that you remove ALL connections from the relay module and its power supply to the Uno's ground. So DO NOT connect the 5V relay supply's ground to the Uno. The ONLY connections between the Uno and the Relay Module should be Uno 5V >> Relay Vcc, and then the Uno I/O pins to the relay's IN1, IN2, IN3, IN4. Try this before everything else!

I was not aware that this Thread was about model railways until @steve20016 pointed it out.

I am having problems which may or may not have the same roots and you may be interested in my Thread about it.

Now that I think about it my Title does not mention model trains either - must fix that.

...R

dave-in-nj:
however, the signal lines should be grounded to the UNO is some way to complete the circuit.

No...

Opto LED drive circuit is between relay VCC and the IN pins. Ground is NOT needed for that.
Leo..

Thank you for all of the replies. I will take some time to sort through these options, read all of the external sources provided, experiment and report back with some hopefully good news.

One last thing I thought about... would having the UNO's I/O pins control for example a set of TIP102's (instead of directly connecting to the relay board) so that each TIP102 provides 5v to the relay board input pins work? The TIP102's would provide 5v from the 5v power supply that powers the relay board. Perhaps this would create a degree of separation between the relay board's coils and the UNO board?

Lastly, Wawa:

Wawa:
Correct about the bridge rectifier.

would this bridge rectifier work:

Thank you!

Just a recommendation to start with the simplest potential solution first, which is to disconnect all ground connections between the Uno and your existing relay board and between the Uno and the relay power supply.

moses1592:
would having the UNO's I/O pins control for example a set of TIP102's (instead of directly connecting to the relay board) so that each TIP102 provides 5v to the relay board input pins work?

would this bridge rectifier work...

The Uno pin does not 'provide' power, the relay module does.
The Uno pin just has to switch the tiny (2mA) opto LED current to ground.
Adding a Tip120 is gross overkill, and only overcomplicates things.

Overkill for the bridge too. 1/10 of the voltage/current specs would do.
Leo..

Hi,
The OP has these relays.


Tom... :slight_smile:

I am using the same relay modules.

And it seems that this MegaPoints module (which is based on an Atmeg 328) also uses the same relays.

The only immediately obvious difference is that it has a 12v to 5v regulator on the board.

...R

Post a diagram of your button wiring.

JCA34F:
Post a diagram of your button wiring.

To whom is this addressed?

...R

Robin2:
I was not aware that this Thread was about model railways until @steve20016 pointed it out.

I am having problems which may or may not have the same roots and you may be interested in my Thread about it.

Now that I think about it my Title does not mention model trains either - must fix that.

...R

Yes, after reading your thread, we are having the same problem.

JCA34F:
Post a diagram of your button wiring.

The button wiring is as straightforward as can be. Its a simple on/off, with one lead attached to arduino I/O pin and the other to arduino’s ground, and pin is set as input pullup in the code. There are two of them.