An error occurred while uploading the sketch lỗi

If you keep getting the error below (or a similar one) when trying to upload your sketch, read this article.

An error occurred while uploading the sketch lỗi

Try the troubleshooting steps below in order. If it still fails, contact us and describe what you tried (which steps).

Show verbose output of the Arduino IDE

In File > Preferences do you have the “Show verbose output during: upload” checked?

An error occurred while uploading the sketch lỗi

That might show more details and you can send that output to us.

After each step, check if you can upload.

  1. Reconnect the Arduino, connect it to a different USB port. Select the new COM-port from the Tools menu.
  2. Close the Serial Monitor. In the bottom part of the Arduino IDE or as a separate window, it might still be open (click the ‘X’ to close it).
  3. If there is no value for the COM… port or none of them work, you might have to install the driver.
  4. Disconnect the Arduino, reboot your computer, reconnect Arduino.
  5. Do the lights (LED’s) on the Arduino work? There should be at least one LED turned on if the Arduino receives power via USB. If not, double-check your wiring. If there is still no light on, replace the Arduino or try step 7.
  6. Double-check the settings in the Tools menu: for regular Arduino, set Bootloader to "ATmega328P (Old Bootloader)", for BLE-Nano, set it to just "ATmega328P". Check the other settings too!
  7. Try an empty sketch: Save your current sketch, then restart the Arduino IDE (close all windows, then open the app with a single sketch). Create an empty sketch (File > New). Save that sketch and then try to upload the empty sketch.
  8. Try another Arduino: connect an Arduino directly to your computer with an USB cable, so without mounting it on a breadboard or connecting any wires or components to it. If you do not have another Arduino, remove it from the breadboard and then connect. Make sure the settings match this Arduino (do step 2 again).
  9. Update the driver of your COM-port. Disconnect your Arduino. Go to Windows Device Manager (type in start: ‘device manager’ or ‘apparaatbeheer’). Expand ‘Ports’ (Poorten) and notice the options in there. Now plug-in the USB of your Arduino, and watch which Port is added in this list. Right-click this one and choose ‘update driver’ and then select the option to automatically let Windows search for available drivers.
  10. The same as above, but instead of ‘update driver’, choose ‘remove device’ while your Arduino is connected. Then disconnect your Arduino and reconnect it again, this will force Windows to reinstall the drivers for this COM-Port. If your board uses a CH340 driver, check this page for (re)installing that driver.

Not in sync
"avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00"

May occur randomly, especially if you have multiple arduino sketches open. It means the port is busy and cannot be accessed at the moment. This is nothing too serious, though. Reconnecting the Arduino or restarting your computer often resolves the issue.

Can't open device
"ser_open(): can't open device "\.\COM6" … "

This means the driver of this port has crashed or cannot be found. This is often caused by incorrectly disconnecting your Arduino. NEVER rewire your breadboard when the Arduino is connected to your PC. This can damage the Arduino, and more importantly, your computer!

Restarting your computer might help.

Other things to try

As a test, connect the other Arduino (our kits come with 2 of them), just the board itself, no need to mount it on a breadboard. Check that you select the proper Processor (Tools > Processor): the regular Nano needs “ATmega328P (old bootloader)”, the Nano BLE needs the regular one (ATmega328P).

If connecting the other Arduino (without being mounted on the breadboard) works, there are 2 possibilities: 1. you have a wiring problem (your wires cause the Arduino mounted on the breadboard to malfunction) 2. the Arduino mounted on the breadboard (that does not work) is defective.

In case of 1: double or triple check the wiring! In case of 2: replace the Arduino on the board with the working Arduino.

I am learning to receive data from the UART pins of the Arduino. I am using a SPEC Gas Sensor for the same. Here is the simplest code I could write.

void setup() {
  Serial.begin(9600);
}
void loop() {
  if(Serial.available()>0) {
    Serial.print(Serial.available());
  }
}

The code verifies but when I try to burn this code in the Arduino Uno, I get the following error after it says that the code uses 5% of the storage space.

Sketch uses 1744 bytes (5%) of program storage space. Maximum is 32256 bytes.
Global variables use 184 bytes (8%) of dynamic memory, leaving 1864 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x1e
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x66
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x7e
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x06
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x86
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xf8
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x06
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x7e
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x86
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x9e
An error occurred while uploading the sketch

I checked online for a solution but they provide basic answers like restarting everything. It doesn't work.

Please help.

dda

6,1072 gold badges25 silver badges34 bronze badges

asked Aug 18, 2017 at 22:01

Vishesh ChananaVishesh Chanana

1153 gold badges5 silver badges11 bronze badges

0

When uploading a sketch, you must disconnect the serial I/O pins from any devices before an upload succeeds.

The Uno shares the two hardware serial pins with the USB that's used to perform sketch upload, so nothing else can be connected to the serial pins (0 and 1).

If I recall correctly, you only need to disconnect the Rx pin, but that's from memory, so disconnect both and it'll almost certainly work.

answered Aug 18, 2017 at 22:20

When uploading a sketch check whether arduino board was set into correct configuration.such as selecting the uno board ,serial port ,even when you constructing a model of bidirectional it work when u assign the SAM board.

Why can't I upload a sketch?

It doesn't work. Please help. When uploading a sketch, you must disconnect the serial I/O pins from any devices before an upload succeeds. The Uno shares the two hardware serial pins with the USB that's used to perform sketch upload, so nothing else can be connected to the serial pins (0 and 1).

How do I upload a sketch to my Arduino IDE?

Select the port of the board from the menu in Arduino IDE. The port might have changed after the previous step, so make sure to verify that it is selected. Now try uploading the sketch to your board again. Couldn't find a Board on the selected port. Check that you have the correct port selected.

What do I do if my sketch doesn't compile?

When there is an error the IDE will print relevant information in the console. Learn how to resolve common errors. Check your sketch for errors. Click the Verify button to compile your sketch without uploading it. If you still get an error, see If your sketch doesn’t compile. Check your board and port selections.

What is the maximum size of a sketch?

An error occurred while uploading the sketch. - Installation & Troubleshooting - Arduino Forum An error occurred while uploading the sketch. Sketch uses 928 bytes (2%) of program storage space. Maximum is 32,256 bytes. Global variables use 9 bytes (0%) of dynamic memory, leaving 2,039 bytes for local variables. Maximum is 2,048 bytes.