Installing the Optiboot Loader on an Arudino Nano to Fix the Watch Dog Timer (WDT) Issue

I sat down last night to write a quick test program to make sure I understood how to program the watchdog timer. OK, I haven’t done this in a long time, looks simple enough though, I’ll be done in 20 minutes.

Yeah, right. Three hours later it still doesn’t work and I’ve come to learn there is a problem in the Arduino Nano’s bootloader that prevents the WDT from working correctly. In my circumstance, the Nano ran fine up to the point where the WDT reboots, but the Nano never recovers from the reboot. It just flashed the LED rapidly.

After some research of the problem, I found that if you replace the Arduino Nano’s bootloader with the Optiboot loader, the problem will be fixed, and you have some extra program memory left over as well because the Optiboot bootloader is smaller.

I updated a bootloader several years ago but had no memory of what the process was to install a normal Arduino bootloader, much less a different one. BUT I did have the AVR pocket programmer I had used so at least I had everything I needed!

First I needed to connect the Nano to the pocket programmer. The Nano (or at least mine) doesn’t have ICSP header pins soldered in place. It’s got the holes in the PCB, but no pins. But I really didn’t want to solder on pins mainly because there’s not that good a chance I’ll need to do this again.

So my first step was to connect the Nano to a breadboard and connect the AVR pocket programmer to the correct pins on the Nano. I used this website as a guide to getting the hardware setup correctly:

Here is how I connected it all together. I have written the Nano pins next to the diagram of the AVR pocket programmer pin outs along with the wire colors:

av pocket programmer setup

Once the hardware was setup, I didn’t want to make any assumptions, so first I simply installed a normal Nano boot loader using the Arduino IDE. To do this, first, select the board as an Arduino Nano:


then I selected the programmer which is the USBtinyISP:


and I burned the bootload by clicking on Burn Bootloader:


Once the bootloader was burned, I compiled and uploaded the blink sketch onto the Nano to be sure it still worked.

While I mainly burned the standard bootloader just to be sure I had the AVR programmer setup properly, I was hoping that a newer bootloader might fix the problem. Unfortunately it did not so I had to continue with installing Optiboot.

While researching how to install Optiboot, I discovered the Optiboot loader is actually in my Arduino installation (I’m using version 1.0.6).  Examining the C :\Program Files\Arduino\hardware\arduino directory for the boards.txt file, I found that optiboot is loaded for a few of the boards (like the uno): Uno

but not for the Nano: Nano w/ ATmega328

I decided the easiest way to make use of the existing Optiboot loader was to fix the boards.txt file. Rather than mess with the existing entries, I wanted to create the ‘standard’ Optiboot entries using their boards.txt file.

So I downloaded their boards.txt file from here:

I then copied the contents of that file and appended it to the end of the boards.txt file already on my PC. Now I have a bunch of new boards prefixed with [Optiboot]:


At this point I was ready to upload the Optiboot loader. I selected the board titled “[optiboot] arduino duemilanove or nano with atmega 328”, still used the USBtinyISP programmer, and clicked on burn bootloader with a note of trepidation.

I then uploaded the blink sketch into the Arduino nano and it worked perfect.

I use codeblocks for Arduino for most of my Arduino IDE needs. The Optiboot board is not an option for codeblocks. During my research I found that once Optiboot is installed, the Nano can be programmed as if it were an Uno. So I changed the board type to Uno and uploaded the blink sketch again. It uploaded and ran fine.

Now that the bootload was replaced, the last test was to try my WDT program. SUCCESS! It now runs on the Nano just as it does on the Uno.

My last step was to write Uno over the Nano silk screen using a find sharpie. That is to remind me I will need to select the Uno board type for this card. I’m sure I’ll still forget, but hopefully will remember a little quicker.,



This entry was posted in c-arduino. Bookmark the permalink.

11 Responses to Installing the Optiboot Loader on an Arudino Nano to Fix the Watch Dog Timer (WDT) Issue

  1. lafudoci says:

    Thank you for sharing these useful instruction.
    This totally solved my problem!
    I rewrote this instruction in my blogger, because there is no such kind of information in chinese.

  2. Nano says:

    Do the Nano’s still have the WDT bug?

  3. Nano says:

    Thanks, your the man Dan.

  4. Nano says:

    Yes the Nano clones I am using still have the WDT bug. With your sketch it just rapidly flashes the LED when it should be doing the reset. It has taken me all day to get Optiboot loaded and needed Nick Gammons sketches to do it. Even tried using the old 1.0X IDE but no joy. Your last paragraph is quite important about the Nano’s now being ‘Uno’s’. After all the work to get Optiboot loaded I was then struggling to load any sketches. Reverted to Xloader rather than the IDE but realised I had to pick Uno and now it works ok with the IDE. Thanks for your inspiration for me to finally add WDT to my Nano projects.

    • Dan TheMan says:

      You’ll be glad you did. I’ve got 2 Nano’s and an ATTiny monitoring various environmental signals around my house and I’ve not had to ever ‘reset’ them. The 2 Nanos have been running for several years now.

  5. Raufjay says:

    Thanks for this wonderful info. My question is, Uno has 6 analog inputs, whereas nano has 8. Pertaining nano as Uno, will still support A6 and A7?

    • Dan TheMan says:

      I don’t know for a fact, but since both are based on the ATMEGA328 chip I would expect it to work. Chances are the Uno just doesn’t have the extra analog pins connected to the board for access.

  6. edl says:

    Thanks heaps! Have cleared up the watchdog bug added another 1.5k of space for my sketches plus everything now loads/boots faster. On the Mac the instructions are bit different where you will find the boards.txt within the with a right click to Show Package Contents. Combining the txt files is exactly the same. Now my bootloader of choice!

    Needed to hard set the path for Arduino 1.6.7 per entry in the new txt:

    Needed to add for Arduino 1.6.7 per entry in the new txt:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.