Reset command

Is it possible to use a reset command in the code to reset the Arduino? What command would that be?

One way of doing a software reset is to enable the watchdog timer and let it timeout. A google search should turn up code examples for doing this.


Was thinking on putting a small relay to do actual button pressing and controlling it by a digital output high command. ;D

I just linked from a digital pin to the reset pin, with a pull down resistor. When you want to reset just set the digital pin high. I had my test set up so that I could send a reset command through the serial link. Is this what you’re after?

This seems to come up from time to time, but the Atmel do say that using a pin to reset the chip is not good practice.

You should not try to use another pin of the AVR to pull the external RESET line. The pins of the AVR are tristated halfway through the minimum reset time, this releases the RESET line and hence nothing happens.

There is example code for the preferred way to do a software reset here:

Thanks DaveAK and mem. Both good solutions, one hardware and one software! I think i will try the software one first if fail the hardware one should do the trick.

huh? Perhaps my previous post wasn't clear. The company that designed the chip say that you shouldn't use a pin to do a reset

It may work for some, but why do something the designers say is wrong?

Aha, Did read your post but just checked the link without reading to carefully. So software it is, thanks again mem.

cheers MEM

I got following from the link you provided and it works great.

#include <avr/io.h>
#include <avr/wdt.h>

int main(void)
while(1) {};

hmm yea the code does work, but
now i can’t load any sketch to the arduino anymore…
It does reset itself that quick that the sketch
can’t get uploaded…

What can I do?


Couldn't one use the same hardware trick that the Arduino IDE uses to reset the chip? Wire a .1 cap from an output pin and toggle it? Maybe I'll try and breadboard up an experimate and see if it works later today. Have a cold today and feel like c**p. :'(


Bringing a old post to life again.

Can not really figure this code out

#include <avr/io.h>
#include <avr/wdt.h>

int main(void)
while(1) {};

It leads my arduino to freeze, flashing the “L” led in a high rate.
Logically it is reseting my arduino every 30ms, but i only want it to reset it once.
What am i doing wrong.

Found some more information on this, see text below.
All is pointing at the watchdog, seems as it needs to be disabled otherwise it stays on and continually resets.
Still i can not find a way of making the code working,anybody having time or knowledge to point me the right way?

How do I perform a software reset of the AVR?
The canonical way to perform a software reset of the AVR is to use the watchdog timer. Enable the watchdog timer to the shortest timeout setting, then go into an infinite, do-nothing loop. The watchdog will then reset the processor.
The reason why this is preferable over jumping to the reset vector, is that when the watchdog resets the AVR, the registers will be reset to their known, default settings. Whereas jumping to the reset vector will leave the registers in their previous state, which is generally not a good idea.
CAUTION! Older AVRs will have the watchdog timer disabled on a reset. For these older AVRs, doing a soft reset by enabling the watchdog is easy, as the watchdog will then be disabled after the reset. On newer AVRs, once the watchdog is enabled, then it stays enabled, even after a reset! For these newer AVRs a function needs to be added to the .init3 section (i.e. during the startup code, before main()) to disable the watchdog early enough so it does not continually reset the AVR.
Here is some example code that creates a macro that can be called to perform a soft reset:

#include <avr/wdt.h>


#define soft_reset()        \
do                          \
{                           \
    wdt_enable(WDTO_15MS);  \
    for(;;)                 \
    {                       \
    }                       \
} while(0)

For newer AVRs (such as the ATmega1281) also add this function to your code to then disable the watchdog after a reset (e.g., after a soft reset):

#include <avr/wdt.h>


// Function Pototype
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));


// Function Implementation
void wdt_init(void)
    MCUSR = 0;


After some more searching on the watchdog i found a solution :).

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

And if you read the rest of that thread you'd see why jumping to address 0 is not really a reset and not recommended.

All that does is start the code over, it doesn't reset the chip - an important distinction.

Using watchdog to reset can cause annoying loop when watchdog is retriggered during boostrap. I think watchdog should be disabled when entering bootstrap code.