Starting the code back from line 1 after software reset

Hi, I am using Arduino MKR1500 and I am running a watchdog timer. This is just a simple test code I am running(using the code from here). When I run the modified code

#include <WDTZero.h>

WDTZero MyWatchDoggy; // Define WDT  

void setup() {
  int t = 20; //Initialize serial and wait for port to open, max 10 seconds
  while (!Serial) {
    if ( (t--) == 0 ) break;
 Serial.print("\nWDTZero-Demo : Setup Soft Watchdog at 32S interval"); 
 MyWatchDoggy.setup(WDT_SOFTCYCLE32S);  // initialize WDT-softcounter refesh cycle on 32sec interval

void loop() {
  unsigned int t = 0;

  Serial.print("\nWatchdog Test1 - run 60 seconds with a WDT.clear()\n");
  for (t = 1; t < 60; ++t) {
    MyWatchDoggy.clear();  // refresh wdt - before it loops

  Serial.print("\n\nWatchdog Test2 - Free run wait for reset @32s\n");
  for (t = 1; t > 0; ++t) {
Serial.print("\nYou will never read this line");


void myshutdown()

Serial.print("\nWe gonna shut down ! ...");

The code shows the following output:

11:40:54.794 -> WDTZero-Demo : Setup Soft Watchdog at 32S interval
11:40:54.794 -> Watchdog Test1 - run 60 seconds with a WDT.clear()
11:40:55.724 ->
11:41:51.064 -> 
11:41:51.064 -> Watchdog Test2 - Free run wait for reset @32s
11:41:52.003 ->
11:42:22.285 -> We gonna shut down ! ...

After that the I hear the USB disconnect and connect sound(ensuring the Arduino reset) but after that the code never starts running again and the serial monitor is blank. How do I make it keep counting down and then reset itself after the timer ends and I can see in the serial monitor that counter again?

I have not used a watchdog timer, but be aware that NONE of your program variables are ever reset to the initial values that are there when your program is first loaded. They still contain the values that were there when the timer expired. Perhaps that is causing your problem.

1 Like

Did you try restarting the serial monitor? I suppose the monitor will not establish the USB connection automatically after it has been lost.


Hi MacroBahner, I never guessed that I had to restart the serial monitor. I always thought it should auto-restart and should start printing the data.
I restarted the serial monitor and there was the output running.
Thanks a ton!

I already had similar problems with a Leonardo/Micro. I suppose this is a general problem with all Arduinos with native USB. When they are resetted the USB connection gets lost and is reconnected. And the serial monitor cannot cope with that.

1 Like

Some terminal programs will reconnect. Under Windows, TeraTerm is the one I'm aware of.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.