Two Ways to Reset Arduino in Software

486,320

157

60

If you want to RESET Arduino from the beginning without manually pressing the RESET button, there are a few ways. Here are two ways, using minimal wiring / circuitry. 

Step 1: Using 1 Wire Connected to the RESET Pin

1. electronically, using only 1 wire connecting an OUTPUT pin (12 in this example) to the RESET pin. (see the circuit)

In this example, pin 13, connected to the internal LED pin 13 is blinking. Pin 12 gets connected to the RESET pin by one wire.
-Typically, this would be a problem because when the application starts up, all pins get pulled LOW. This would therefore disable Arduino from every running. BUT, the trick is: in setup() function, the FIRST thing that happens is we write HIGH to the pin 12, which is called our reset pin (digitalWrite(resetPin, HIGH), thereby pulling the Arduino RESET pin HIGH. 

Step 2: Using Just Software

In this example, you do not need any extra wiring. We initialize the reset function, then call reset.

void(* resetFunc) (void) = 0;//declare reset function at address 0
...
resetFunc(); //call reset 

Share

    Recommendations

    • Faux-Real Contest

      Faux-Real Contest
    • Paper Contest

      Paper Contest
    • Epilog X Contest

      Epilog X Contest

    60 Discussions

    0
    None
    Antony21

    Question 7 months ago

    Estou tentando fazer pelo Arduíno mega um botão de reset por um botão, para resetar um tempo quando apertado, porém a programação não esta funcionando.

    0
    None
    stevenk37

    3 years ago

    Well.. #1 is not really a software solution, is it, if you have to wire pins.. Also, this is not an advised solution, according to what I've read before.

    #2 Is just a hack that anyone could come up with, but still doesn't provide a real watchdog functionality (you have to trigger it, and thus can only be used as a reset method, not a WD (which seems to be what sme of you guys need).

    Let me give some details on the built-in arduino WD (yes, really) that can be used both as WD or as a reset device.

    You can set it from 15ms to 8s range. You need to reset it in software or otherwise it will trigger a reset (reverse to #2 method).

    Here's how to use it;

    #include <avr/wdt.h> //should be in any adruino IDE

    void setup() {
    wdt_disable(); //always good to disable it, if it was left 'on' or you need init time
    //do some stuff here
    wdt_enable(WDTO_8S); //enable it, and set it to 8s
    }

    void loop() {
    //do some stuff here
    wdt_delay(5000) //instead of delay, i made my own delay to reset the WDT
    }

    //this makes sure the WDT is reset immediately when entering the
    //function, but we can still benefit from a real 'delay'.
    //upon leaving the function, we reset it again.
    //i realize timing will be loose, you can always do something with
    //millies() if you need strict timing.
    //you might also need to adjust the '1000' if you WDT is shorter

    void wdt_delay(unsigned long msec) {
    wdt_reset();

    while(msec > 1000) {
    wdt_reset();
    delay(1000);
    msec -= 1000;
    }
    delay(msec);
    wdt_reset();
    }

    //to reload the board, you only have to delay > WDT
    //another option is to set the WDT very short, and do a short delay

    void wdt_reload() {
    delay(8001);
    }

    13 replies
    0
    None
    AndreC115stevenk37

    Reply 9 months ago

    I did that, by using the WDT approach, and the board got stuck; I'm even unable to program the original code with Pololu USB programmer. Unfortunatelly, the board is battery powered and designers did not provide a RESET button, therefore it seems I'm in a big trouble. Did I miss something, or there are another way to put it to work again?

    0
    None
    stevenk37AndreC115

    Reply 8 months ago

    what kind of board is this? it seems not a 'standard' arduino? eitherway if it uses the same ATmega328P-like chip, you should be able to find the reset pin on the processor and use that..? if you're stuck, and cannot program it, try the icsp connectors, which also have a reset pin..

    0
    None
    AssiniH2stevenk37

    Reply 1 year ago

    It is not working...

    After few seconds, LED on pin13 is blinking...

    0
    None
    stevenk37AssiniH2

    Reply 1 year ago

    Please make sure the board (and the bootloader!) support watchdog.

    0
    None
    ChandanD19stevenk37

    Reply 1 year ago

    Hi Steven,

    Above code is not working. Everytime reset is happens but if the watchdog overflows it is going to infinite reset loop(not once)

    0
    None
    stevenk37ChandanD19

    Reply 1 year ago

    Please make sure the board (and the bootloader!) support watchdog. This seems to happen with Arduino Pro Mini.

    0
    None
    gussmithstevenk37

    Reply 1 year ago

    This is interesting. Is the reset by the watchdog timer the same as if you would press the reset button?

    0
    None
    stevenk37gussmith

    Reply 1 year ago

    there are differences, can't remember exactly. I think it has to do with some pin state/config after the reboot.

    0
    None
    stevenk37gussmith

    Reply 1 year ago

    this has been discussed on the arduino playground. see https://playground.arduino.cc/Main/ArduinoReset

    0
    None
    FirstN1stevenk37

    Reply 2 years ago

    I am sorry to say this, but many times the comments are much more useful than the article itself. Thank you.

    0
    None
    pinp2stevenk37

    Reply 2 years ago

    Thank you stevenk37 for an Arduino Watchdog. It is does the trick I need.

    It would be good if you would create a separate entry about it cause not all people read through comments :)

    0
    None
    codebeat

    1 year ago

    resetFunc is a pointer to an invalid address! That's the reason the device 'resets', in fact it crashes. Don't rely on this malfunction method and maybe it can damage your device at the long run.

    0
    None
    FellaMegaOld.

    1 year ago

    http://www.atmel.com/webdoc/avrlibcreferencemanual/FAQ_1faq_softreset.html