Unable to upload a sketch

good afternoon guys, i am having a issue where i am getting a warning where i try to upload a sketch it says Sketch this is the warning

avrdude: ser_open(): can't set com-state for "\.\COM4"

i have manually tried to update my drivers and it says that the best drivers are installed, i have also uninstalled the com ports and allowed windows to reinstall them, i am using windows 11, any help would be appreciated

Hi @Mushroom_man

There were some previous reports of this "can't set com-state for ..." error occurring specifically when using boards like yours that have the CH340 USB chip. It seems that a driver upgrade included in a recent Windows update is the cause of this problem.

Some of the affected users have found that uninstalling and reinstalling the CH340 device fixed the problem. I'll share the instructions you can follow to do that:

  1. Close Arduino IDE if it is running.
  2. Connect the Arduino board to your computer with a USB cable.
  3. Open the Windows Device Manager.
  4. Select View > Devices by type from the menus in the Device Manager window.
  5. Open the "View" menu in Device Manager.
  6. If there is a to the left of the "Show hidden devices" menu item, click on "Show hidden devices" to disable it.
  7. Open the "Ports (COM & LPT)" section of the Device Manager tree.
  8. You should see a port identified as "USB-SERIAL CH340 (COM_n_)" under the "Ports (COM & LPT)" section (where "COM_n_" is some serial port e.g., COM4). Right click on that item.
    A context menu will open.
  9. Select "Uninstall device" from the context menu.
    An "Uninstall Device" dialog will open.
  10. Check the box next to "☐ Attempt to remove the driver for this device" in the "Uninstall Device" dialog.
  11. Click the "Uninstall" button.
  12. Wait for the uninstallation process to finish.
  13. Unplug the USB cable of the Arduino board from your computer.
  14. Wait for the Device Manager tree to reload.
  15. Connect the USB cable of the Arduino board to your computer.
  16. Wait for the "USB-SERIAL CH340 (COM_n_)" port to reappear under the "Ports (COM & LPT)" section of the Device Manager tree.
  17. Select File > Exit from the Device Manager menus.

My experience is that the device will be reinstalled automatically by Windows after you plug the board back into the computer, as indicated by the "USB-SERIAL CH340 (COM_n_)" port reappearing in the last step of those instructions. However, it is maybe possible that the complete driver removal will actually have been accomplished by the above instructions, in which case it would be necessary to reinstall the driver. If this happens to you, please let me know and I'll provide instructions you can follow to install the driver.

Now start Arduino IDE again and repeat whatever you were doing before when you encountered that error. Please reply here to let us know whether the error still occurs.

good moring, thank you for the reply, it is now uploading but giving a error saying port monitior error open failed could not connect to com 3, but the sketch did upload, it however does not allow the serial monitor to open

I'm glad it is uploading at least now. That is definitely progress!

Check to make sure you have the correct port selected in the Tools > Port menu in Arduino IDE. Previously you were using COM4 so it is a bit unexpected that the Serial Monitor error is referring to COM3. It is possible for the COM port of a board to change, but it is not so common with the boards that use a dedicated USB chip like the CH340.

Hi sorry i should have mentioned this as i changed the com port to test so it says the same thing on com 4

Hi guys its back to nit uploading at all i dont actually know what the do now please help

I'm going to ask you to post the full output from the upload when in verbose mode.


:exclamation: NOTE: These instructions will not solve the problem. They are only intended to gather more information about the problem.


Please do this:

  1. Select File > Preferences... from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Uncheck the box next to Show verbose output during: compilation in the "Preferences" dialog.
  3. Check the box next to Show verbose output during: ☐ upload.
  4. Click the OK button.
  5. Attempt an upload, as you did before.
  6. Wait for the upload to fail.
  7. You will see a "Upload error: ..." notification at the bottom right corner of the Arduino IDE window. Click the COPY ERROR MESSAGES button on that notification.
  8. Open a forum reply here by clicking the Reply button.
  9. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code tags icon on toolbar
  10. Press Ctrl+V.
    This will paste the error output from the upload into the code block.
  11. Move the cursor outside of the code tags before you add any additional text to your reply.
  12. Click the Reply button to post the output.

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