Troubleshooting sketch reboots

I've created a sketch which waits for an HTTP GET request, and using the info in that request to toggle 4 relays on/off. I'm using an ATMega328 with the arduino bootloader on it, on a custom perfboard that is basically a boardduino. Connected to this is an official Ethernet shield. The Arduino is powered by an external 5vdc power supply, which is connected directly to the Arduino's VCC and gnd pins. There is also a 10uF cap between the power supply and Arduino (again, just like a boardduino setup). The analog pins on the arduino are used to control a 4 relay board from SainSmart (http://www.amazon.com/SainSmart-4-Channel-Relay-Module-Arduino/dp/B0057OC5O8).

On startup (in the setup() part) my code switches all the relays on/off 3 times. It then goes on to the loop() where it waits for a GET request and switches relays accordingly. For testing, I simply use a web browser to make requests to the Arduino. This works fine for anywhere from 2-10 calls, but at some point, the Arduino always resets. When it does, it will either a) go through the full setup() successfully and then start working again or b) get part way through the setup() (flash all relays 1-2 times) then reset again several times before finally making it through the full setup().

I thought this may be a power supply issue, so I have tried powering the Arduino with 5v from a benchtop power supply. Same results. I also tried using a scope to watch the voltage levels. I connected the probe to the positive leg of the capacitor on the board and the negative to gnd. This didn't show any power fluctuations either.

I've also include some debugging code in my Sketch to see if the arduino was running out of RAM, but this doesn't seem to be the case. Additionally, the Arduino will reset even if making the same GET request to it repeatedly, which means it is running through exactly the same code as when it is working.

My next steps is to recreate the setup on a breadboard (though, this is how the project started and it worked fine before) and see if it still resets. Any other ideas or troubleshooting ideas?

PS: My current sketch code is attached.

splunklight_working.ino (7.36 KB)

It really sounds like a program problem and not a hardware problem.

the arduino reboot loop()

I just had a similar problem, it was with using a lot of strings....

The guys here helped me out saying i should use progmem, this fixed my reboots. :slight_smile:

I've put a bunch of additional filtering caps (OK, 4) on my board and also cleaned up the perfboard to make sure there was no way there could be an intermittent short. So far, so good.

I do have several Strings (objects, not char strings) and I have seen this cause RAM issues before. However, all my strings are configured to be stored in flash, not RAM, so it should not be an issue here. I've also included some debugging code to report on the minimum amount of free RAM at any point in the sketch, and so I have quite a bit still free. Admittedly though, this wouldn't help if the Arduino hit some code the spontaneously caused it to run out of RAM.

Like I said, things seem to be working better now with my physical tweaks, but I would appreciate someone reviewing my if/then statements to make sure the math I am using isn't crazy.