How do I auto reset?

I'm using a GSM shield to upload data to a server every few minutes. But every couple of hours it just stops and I have to reset the arduino.

How can I build in a way to automatically reset the arduino (and maybe the GSM shield) if there's a problem?

If your arduino stops working or responding as expected, it is most likely a bug in your code, or it could be memory related. You are in control of this, so rather than trying to reset the Arduino, ensure that the code is solid. Otherwise the Atmega328 MCU has a built in watchdog timer. You could read the datasheet and try and figure out how to use it in your application.

A quick look at the GSM information http://arduino.cc/en/Main/ArduinoGSMShield shows that it has a control pin connected to the Arduino's Pin 7. Try toggling this pin for a set amount of time to see if the GSM module resets.

So does the watchdog timer automatically work, I don’t have to do anything in the code?

Also I should have specified that I’m using a SIM900 module so not sure about the Pin 7

No, by default the watchdog is disabled. Here is a thread with information on it: http://forum.arduino.cc/index.php?topic=63651.0 Also: I don't think the standard delay function resets the watchdog, so if you are using delays longer than the configured reset period, your arduino will reset. If you are using the wathcdog, you will need to have watchdog reset commands spread throughout your code, and ensure that your code resets the watchdog before it times out, unless you want your arduino to reset, in which case, you can just enter an endless loop that does nothing.

As far as your GSM module is concerned, try figure out if it has a reset pin, if not, you could reset it by controlling its power through an IO pin and a transistor/FET, since it looks like it can draw up to 2 Amps in short bursts. By the looks of it, it has an external power connector and a switch to switch between Arduino power and external power, so it should be relatively easy to wire up it's external power source to be controlled by an IO pin.

In all honesty, there must be another reason for it to stop working so often. before you go down this route, try and figure out first if there isn't something else you might be doing wrong. Go back to the basic examples, and see if they run for more than a few minutes. If they do, then you must have a bug in your code, and you are trying to solve it by hitting it with a very large hammer.

I've made some tweaks to the code so that it now disconnects and re-connects every time it wants to send data which seems to have fixed the issue but I would still like to have procedures in place just in case it does crash.

I think I agree with you that a transistor to the power supply would be the best way to reset the GSM shield.

Thank you very much for that link to the watchdog timer info. I think that will definitely be a thing to do. Only one slight hitch.... I'm using Rocketscream's Low power library (https://github.com/rocketscream/Low-Power) in order to put the arduino to sleep between readings. This makes use of the watchdog timer so I fear there may be some clashes? Also I wonder whether the GSM might take more than 8S to transmit.

What are your thoughts?

Thank you again for the information you've already provided, it's been very helpful.

Many shields have a software controlled power on and off feature (you didn't provide a link so I don't know if yours does). Even when 'hung' it may respond to this so every so often send an AT command and wait for a response. If no response within a certain time then power cycle the shield.

dannable: Many shields have a software controlled power on and off feature (you didn't provide a link so I don't know if yours does). Even when 'hung' it may respond to this so every so often send an AT command and wait for a response. If no response within a certain time then power cycle the shield.

Yes I think there is an AT command for that. Here's the shield I'm using http://www.tinyosshop.com/index.php?route=product/product&product_id=464

Any thoughts on using the watchdog timer alongside the sleeping library?

You could disable the watchdog when you go to sleep and re-enable it when you wake up?