Unable to upload sketch to arduino UNO after uploading a specific code.

Some friends of mine contacted about this problem that occured during a University project they were working on. After uploading the code below, every uploading attempt gives an error. Usually this:

Arduino: 1.8.4 (Windows 10), Board: "Arduino/Genuino Uno"

Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x51
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x51
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x51
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x51
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x51
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x51
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x51
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x51
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x51
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x51
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I suspect that the reason behing this is the fact that there is no delay between the serial prints and that keeps serial constantly busy. The code works fine without the prints. I saw a few similar posts, but nothing worked so far.

Some of the suggestions we already tried:

  1. Different IDE versions.
  2. Different computers.
  3. Pressing reset button before uploading. Actually reset didn't seem to work at all (no LEDs blinking).
  4. Plugging the cable right before upload starts. Some people claimed that this did the trick for them, but I tried many times with no success.
  5. Different Arduinos. Both now have the same issue.
  6. Checking the port that the arduino is (The only available I mean).

Their project is now over (thankfully I had a spare Arduino) but i have two useless in my hands and i was wondering if there is some way of fixing them. It seems like a waste to just throw them away.

P.S. I tried these with no connections on the arduino, just the usb cable.

LightSensorTesting2.ino.ino (5.64 KB)

Bill_98:
I suspect that the reason behing this is the fact that there is no delay between the serial prints and that keeps serial constantly busy.

I've run many programs that did this on my Unos over the years and it never caused a problem.

Remove any connections to pins 0 and 1 on your Arduino board. These pins are used for communication with your computer, including uploads. Connecting anything to these pins can interfere with uploads.

Make sure you have selected the port of your Arduino board from the Tools > Port menu.

Sometimes the port will be labeled with the board name in the menu. Other times it will not. If you don’t know which port is your Arduino, you can find it like this:

  • Unplug your Arduino board from the computer.
  • Tools > Port
  • Note the ports, if any, listed in the menu.
  • Close the Tools menu. The ports list is only updated when the Tools menu is re-opened, so this step is essential.
  • Plug your Arduino board into the computer.
  • Tools > Port - The new port listed in the menu is your Arduino board.

Sorry, I suppose I should have mentioned these as well in my post, I will edit it to include them.

I think the only remaining thing you can try is burning the bootloader.

You will need an ISP programmer. If you don’t have a programmer, you can use a spare Arduino board as an "Arduino as ISP" programmer. Although the "Arduino as ISP" only works for programming targets of the AVR architecture, you can use boards of any architecture as an "Arduino as ISP" programmer.


The following instructions are for using an Arduino board as an "Arduino as ISP" programmer. If you have a dedicated programmer, you can skip to the next set of instructions.

Make the following connections between the Arduino board you will be using as the programmer and the target. Refer to the "Connections" table on the SPI library reference page to determine the pins:

| Programmer | | Target |
| - | - |
| ----------- | |------- |
| MISO | | MISO |
| ----------- | |------- |
| VCC | | 5V |
| | | (VCC on 3.3 V boards) |
| ----------- | |------- |
| SCK | | SCK |
| ----------- | |------- |
| MOSI | | MOSI |
| ----------- | |------- |
| 10 | | RESET |
| ----------- | |------- |
| GND | | GND |

Connect the programmer board to your computer with a USB cable.

File > Examples > 11.ArduinoISP > Arduino ISP

Select the port of your board from the Tools > Port menu.

Sketch > Upload

Wait for the upload to finish.

You are now ready to burn the bootloader using your "Arduino as ISP" programmer.


Instructions for burning the bootloader:

  • Connect an ISP programmer to the ICSP header on your Arduino board.
  • Select the target board from the Tools > Board menu and any other custom Tools menus (e.g. Tools > Processor).
  • Select the appropriate programmer from the Tools > Programmer menu.
  • Tools > Burn Bootloader
  • Wait for the process to finish successfully.

I used an arduino as programmer and connected it's ICSP header with the targets ICSP header but I get this error

Arduino: 1.8.4 (Windows 10), Board: "Arduino/Genuino Uno"

F:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CF:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -cstk500v1 -PCOM8 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xDE:m -Ulfuse:w:0xFF:m 

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "F:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM8
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000 (retrying)

Error while burning bootloader.
Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I also tried using the pins 11,12... of the target but again it didn't work. Finally I also tried without using the headers like this


Again same error.
I checked the "Arduino as ISP" programmer in the tools and Arduino UNO on the board, I found no option about the Processor though.

The connections are correct. You might check your jumper wires to make sure they have continuity through them. An occasional jumper wire has a bad connection and doesn't conduct electricity. Other than that, the ATmega328P is probably dead. I noticed the sketch you posted is about motors. Connecting a motor incorrectly to an Arduino board is a common way to destroy them.

Bill_98:
I found no option about the Processor though.

My instructions were intended to work for a variety of boards. The Uno doesn't have any custom Tools menus like Tools > Processor, so all you need to do is select Tools > Board > Arduino Uno.

All jumper wires returned a resistance of 2-3ohms, so I suppose the problem is not there. It seems it is time to start looking for some new arduinos. Thanks for the quick replies and the detailed explanations.