Hi,
Overview:
I have an Uno running a control box with a few simple inputs and outputs for a Rube Goldberg machine. It doesn't sound important, but the machine is for a theater production and will be running 8 times a week for at least the next year. In a nutshell, the code receives a mechanical relay input signal (connecting ground to an input pullup pin) which signals the machine to start. There are 7 outputs to relays on a sain smart 8 channel opto-isolated relay module (all low signals) (link to relay module below). The arduino only powers the signal to the opto-isolator, not the actual relays. The relays themselves are powered from a regulated 5V, 3A power supply (the same that supplies power to the arduino). The relays control various components such as VFDs, pneumatic solenoids, and electronic latches. Everything is connected to the arduino with a screw terminal shield.
There is also one other input signal (a micro switch connecting ground to an input pullup pin) which lets the machine know once a specific operation within the machine has occurred. All the outputs are timed off of these 2 input signals (including a backup timer if the second signal isn't received). They shut off after about 20 seconds until the machine is triggered again.
Problem:
Once during testing and now once after being installed (so probably less than 5% of the time), the code seems to freeze and not respond to any inputs or the timers inside the code. It's very difficult to replicate the problem given it's inconsistency and because the machine is now installed in another city. I've set up a breadboard emulating the inputs and outputs, but I can't seem to be able to get the error to happen for me.
The one time it did happen during testing, I was unable to get anything to respond and had to end up disconnecting power. Once powered back on, everything worked normally. There are no while loops (only if statements) inside the code, so I can't imagine how it could be getting stuck. It also only uses about 11% of the program storage space and 6% of the dynamic memory, so I wouldn't think memory is an issue either. But it's very possible that I'm missing something in the code that could be causing the problem. The code is attached. It's pretty long, but any hints as to something that looks off would be helpful.
Potential Issue:
About my only guess is that maybe the problem is caused by the power supply being shared with the relay board. Since the arduino is powered right to the 5V pin (not through the internal regulator) could a spike or dip in the voltage from relays turning on an off cause an issue like this? The power supply is a Omron S8VK-G01505 switching 5V power supply (link below). It should be more than capable of powering everything, but maybe the relay's impedance could affect the supply voltage. I just don't know enough about it to know if this is reasonable. If so, I can put a separate power supply in for the arduino.
Thanks in advance for any help, and let me know if there's more information I can provide.
8 Channel Relay Module
5V Power Supply
HL11-19-17.ino (11.4 KB)