Arduino Reset via Software

Gaining the opportunity to reset an Arduino via Software is useful to drop back the processor in a well-known state, often if the system is far away, inaccessible or remotely controlled.

For instance, a remote and autonomous weather station (like this) could need a reset cycle execution in case of data server communication loss or in a reaction of a remote SMS (short message) sent by smartphone.

Another requirement could be to reset the entire registers inside the processor and to restart the main cycle to execute the setup or initialization routines.

There is a possibility to set a watchdog (a guardian) that watch over the cycle time of the processor and if a threshold is reached (for example in case of an infinite loop) a reset will happen automatically.

So, there are a lot of reasons to perform a software reset.

Let’s see, in this short article, how to obtain a software reset using a well documented official function that you can find on the Arduino website (arduino.cc). The function is quite simple to implement and simple to call and execute the final Arduino Reset via Software.

The first step we need to do is a function declaration at any point in our code but is mandatory to declare before the setup() function:

// Arduino Reset via Software function declaration
//... it is a special function that point to zero register
void(* resetSoftware)(void) = 0;

After that, the function is available, so in any moment and according to our code need we could recall anywhere, any time calling it direclty by name, just a classic and simple function:

void loop() {
...
...
resetSoftware(); // immediatly execute the processor reset
...
...
...
}

Here an example on how to execute a reset based on external events generated by a character coming through serial port:

String var = "";
 
void(* resetSoftware)(void) = 0;
 
void setup()
{
  Serial.begin(9600);
  Serial.println("Arduino Starting");
  delay(10000); // wait 10 seconds
}
 
void loop() {
  // waiting for data on serial port
  if (Serial.available() > 0) {
    var = Serial.readString();
    // if we catch-up the R character..
    if (var.equals("R")) {
    // execute the software reset
    Serial.println("Arduino Reset via Software executed on Serial R event...");
    delay(1000); // wait 1 second
    resetSoftware(); // RESET!
    }
  }
}