On my current project I am experiencing an issue with the Arduino Uno appearing to get reset in the middle of running my sketch. However, it does not seem to be caused by the normal reasons and problem is only occurring in a specific and what seems to me to be an unusual situation. I will try to simplify the situation as much as possible with leaving out relevant details. A very brief summary of my project is: 3 push buttons, 4 LEDs, 4 hall sensors, an 8-relay board controlled by the Arduino, and eight 12-volt 30-amp relays each controlled by a smaller corresponding relay. When no power is applied to the 12-volt, 30-amp relays that are on an entirely different power source, everything works perfectly; however, when I apply power to the larger relays (even if there is no load on those relays), when I release one of the two push buttons that activates one or more of the small relays, the Arduino frequently resets and setup() gets executed and all variables are reset. However, it does not always reset and 2 of the 8 relays are much more prone to this issue even though all relays are wired identically. In the most reliably recreatable situation, only one of the 8 small relays is activated so only 1 of the larger relays is activated. The push buttons are wired using standard 10K pull-down resistors. Pressing the buttons never causes the reset – only when they are released. It seems to me that it could be some kind of electrical noise causing the issue, but I wouldn’t expect turning off a relay controlled by a relay could cause this much of an issue for the Arduino. Because it works perfectly without any issues when the secondary 12 volt circuit is powered off, I don’t see how it could be a problem with my sketch. . I consider myself an experienced beginner when it comes to working with Arduinos.
More details concerning components:
HiLetgo 5V 8 Channel Relay Module with OPTO-Isolated Support High and Low Level Trigger
Either electrical noise in the power leads or an inadequate power supply and "brown-out reset" is almost certainly the problem. If noise is the issue, you need better power supply filtering.
For detailed advice, please post a schematic diagram (hand drawn is preferred), paying particular attention to the power supply arrangement. Post links to the modules and be sure component values are specified.
If it is a power brown-out situation, wouldn't you expect it to occur when the relays are engaged and start using power rather than than when the button is released and the stop using power?
In general use a flyback diode that has the same current rating as the load you are trying to suppress. In your case that will be a 1N4001. However, if you have a relay board as opposed to just a relay then it should be fitted with flyback diodes anyway.
The flyback diodes on the secondary 12 volt circuit seems to have worked. THANKS! Although, I'm still a bit surprised that the EMI problem is making its way back to the Arduino through the first set of relays that I believe do have flyback diodes on that board.