Cannot upload code

Hi. I am trying to do this automated dust bin project for my school project and I do not know how to configure anything. Here is the message I constantly get whenever I try to upload the code I got from a tutorial in youtube.

Sketch uses 4612 bytes (14%) of program storage space. Maximum is 32256 bytes.
Global variables use 241 bytes (11%) of dynamic memory, leaving 1807 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't set com-state for "\.\COM3"
Failed uploading: uploading error: exit status 1

Please note that I am a Mechanical Engineering student who is taking up Basic Electronics, so I do not have a background with these kinds of things. I would appreciate it if you help me with a beginner friendly language. :slight_smile:

I am using Arduino IDE 2.1.0, and I have UNO R3 CH340G+MEGA328P

Hi @coldpansit. There were some previous reports of this error occurring specifically when using boards that have the CH340 USB chip. It seems that a driver upgrade included in a recent Windows update is the cause of this problem.

The affected users have found that uninstalling 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 Device Manager menus.
  5. Open the "View" menu.
  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.

My experience is that the device will be reinstalled automatically by Windows. However, it is maybe possible that the complete driver removal will actually have been accomplished by the above instructions, in which case it will be necessary to reinstall the driver. If this happens to you, please let me know and I'll provide instructions for installing the driver.

Once the port has reappeared in Device Manager, start Arduino IDE again and check to see whether the problem still occurs.

The problem still occurs, unfortunately. Here is the message. I think it's the same.

Sketch uses 3172 bytes (9%) of program storage space. Maximum is 32256 bytes.
Global variables use 200 bytes (9%) of dynamic memory, leaving 1848 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't set com-state for "\.\COM3"
Failed uploading: uploading error: exit status 1

Here is the youtube link of the project I am attempting to do for reference. How To Make An Automatic Object Sensing Smart Dustbin - DIY Project - YouTube

I'm sorry my instructions didn't solve the error. That is unfortunate.

While I was researching the spike in these errors, I saw that some of the affected users were able to solve it by installing an older version of the CH340 driver and then doing a "roll back" to that version. I don't have any suggestions for you about how to go about obtaining and installing the older version of the driver in order to enable that "roll back" though. Maybe one of the other forum users will have some advice about that.

Just to confirm whether you can see the COM3 port in Device Manager-Ports

It should appear and disappear when you plug the USB cable which is connected to the Arduino board.

Neither do I :smiley: But the attached one is on my PC since 2018/09/05 as zip; the files in there are even older.

CH341SER.ZIP (198.2 KB)

I also noticed that; can this be a Win11 issue? I did not keep track for which Windows version it was reported. I'm running Win10 and the above driver might have been installed when the system was still Win7.

Yes, I can.

That’s tricky!
The COM port is there, but AVRDUDE can’t access it ?!

Is it open/locked by some other process ? PuTTY or similar?