Arduino

How to fix “Error: avrdude” when uploading code to Arduino

Most of the errors faced by the students when programming the microcontroller using Arduino are of two types one type of errors that arise compiling the code and the other type is the errors that arise when the code is being uploaded to the Arduino. The compilation errors can be rectified easily as they are highlighted by the compiler but the errors that originate while uploading the code are not that easy to rectify because the compiler does not indicate what the cause of the error. So we have listed some of the common errors that you might encounter while uploading the code and have also given the respective solution for each error.

What are the common errors encountered while uploading the sketch to Arduino?

The errors that arise when uploading the sketch to the Arduino are mostly due to issues in the communication between the programming software and the Arduino board. The list of errors that one can expect while uploading the sketch to the Arduino microcontroller

Error 1 : avrdude: ser_open(): can’t open device “portName”: no such file or directory

Error 2 : avrdude: ser_open(): can’t open device “portName”: the semaphore timeout period has expired

Error 3 : avrdude: butterfly_recv(): programmer is not responding

Error 4 : avrdude: ser_open(): can’t open device “portName”: access is denied

Error 5 : avrdude: stk500_recv(): programmer is not responding

Error 6 : avrdude: ser_open(): can’t open device “portName”: the system cannot find the file specified

Error 7 : avrdude: stk500_getsync() attempt X of 10: not in sync

How to fix the errors encountered while uploading the code to the Arduino

In order to avoid the errors listed above one should perform a check list of all the solutions listed below:

Select the correct port and board for uploading the code

Before uploading the code make sure to select the port on which the Arduino is connected and more importantly also correctly select which board you are using The following images show how to select the Arduino board and the port on which it is connected:

Text Description automatically generated

Once you have clicked on the option highlighted in the image above a menu will appear having different boards Simply write the board name you are using in the search bar and select it from the menu and press okay.

Graphical user interface Description automatically generated

After selecting the board, you can connect it to your computer and now you have to select the port in the Arduino IDE on which the board is connected as shown in the image below:

Graphical user interface, text Description automatically generated

When you have selected the port, it will be shown like in the image given below and due to incorrect selection of port or board you can see the errors like the Error 1 or Error 6 in the list given above.

Disconnect the RX and TX pins of Arduino board while uploading the code

The RX and TX pins are the communication pins of the Arduino board, and these pins are also used while uploading the code. Sometimes errors like Error 5 or Error 7 can be encountered because these pins are connected to any other communication device such as a Bluetooth module. So, always while uploading the code to Arduino make sure that the RX and TX pins are not connected to any other device.

Keep open only one window of Arduino IDE

The port name error (Error 4) sometimes occurs when more than one window is open on the Arduino IDE. So, always keep only one tab open while uploading the sketch to the Arduino microcontroller board.

Plug out the USB cable for few seconds and plug it again

If there are still errors even after trying the above solutions, then simply try pulling out the USB cable for the PC and then plug it back in. This fix is mostly related to Error 3 “programmer not responding”.

If the issue persists, then perform the following steps:

Step 1: Press and hold the reset button

Step 2: Keep the reset button pressed and upload the code

Step 3: Wait until the code is uploaded successfully

Step 4: Release the reset button when the code is uploaded

Conclusion

The errors that arise while uploading the Arduino sketches are quite difficult to figure out but one thing is for sure and that is these errors are mostly related to the communication issue between the Arduino programing software and the Arduino microcontroller board So for the ease of the learners we have explained some of the most common errors faced while uploading the sketch and also we have given some fixes for such errors.

About the author

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.