Three ways to reset an Arduino Board by code

Sometimes it can be useful if the Arduino UNO could reboot itself without having to push the reset button on the board.

There are at least two ways to do the job.

Solution one. The dirty solution.

This solution moves the control to the beginning of the program using an assembly statement jump.

It is not a very complete solution because it doesn’t reset all the hardware connected to the Arduino board. Thus means that default configurations of the hardware will not be restored.

Here you are the function to call to reset the Arduino.

arduino

Solution Two. The Watchdog

I think this is the clean way. It uses the watchdog to reset the board, and the job of a watchdog is the reset of a board……

On Arduino Mega 2560, the bootloader could not support the watchdog; to use it, you shall install a bootloader supporting the watchdog.

google for “arduino mega watchdog bootloader”

You can have the same problem with other Arduino boards, so before using wdt_enable, please verify that the bootloader, used by your board, supports wdt_enable

The needed structure are in the avr/wdt.h file, to enable you have to call the function wdt_enable(); it accepts as parameter the time before the board will be reset if no watchdog reset will be issued.

You can choose between several predefined values :

Then to reset the board you have only to implement a short loop, when the timeout expires the system reboots (by francisco). In the following example I have used the minimum value for the timeout. Just call software_Reboot to reboot your board.
#include 

Solution Three. One wire solution

If you are using the watchdog timer for other useful stuff, you can use a wire to connect, via a 1K resistor,a Digital Pin (for example pin12) to the Reset Pin. Then you can use the following code:

If you’ve found useful this post, please, make a visit to my linkedin profile gg1 to help me growing my ranking.
That’s all,

Gg1.

You may also like...

12 Responses

  1. Jon Russell says:

    Hi,

    IIUIC, the AVR datasheet specifically does not recommend the IO pin to reset method. During the reset the AVR sets all its IO to inputs or high Z, which means the reset pulse is not held long enough ? If the data sheet says don’t do it, its probably best not to ?

    Also, IIUIC, the watchdog method isn’t that straight forward either ? you have to disable the watchdog immediately after reboot, as the watchdog setting survives the reboot ? and you'll be stuck in an endless reboot cycle ?

    Regards,

    Jon.

  2. Andrew says:

    Jon,

    To correctly use the watchdog reset, one should reburn his/her bootloader.

    Many use that method to upload a new sketch via bluetooth.

  3. Thiago says:

    Why this code frezzes my arduino mega r3… doesnt reset… only stop!

  4. Michael says:

    On an Arduino Micro with a Caterina bootloader the ‘proper’ procedure is:
    #include “”
    void reboot(void) {
    #define BOOTKEY 0x7777
    #define ADRBKEY *(unsigned short *)0x0800
    cli();
    ADRBKEY = BOOTKEY;
    wdt_reset(WDTO_15MS);
    while (1);
    }

  5. nmiraz says:

    hi i upload the watchdog timer code. it works. but here is a problem. now every 15ms this arduino will be restart. so i can not upload another program. i think my arduino is totally dead. please help me

  6. POMS says:

    My arduino freezed. i used the third method. how to fix it ? :((

  7. POMS says:

    No i mean i used the second method.

  8. Bruce says:

    Solution Two. The Watchdog

    Bricked my Mega!!!!

  9. Robert says:

    void(* resetFunc) (void) = 0;

    and then in the code: resetFunc();

    You’re welcome 😀

  1. December 20, 2014

    […] Watchdog reset […]

  2. June 7, 2015

    […] The 3rd way to reset the Arduino by code (see link here). […]

  3. November 13, 2016

Leave a Reply

Your email address will not be published. Required fields are marked *