Avrdude: ser_open(): can't open device "\\.\COM5": etc

It’s a while since I have uploaded anything, but I’m sure I have never seen this before. The IDE and W10’s DeviceManager both declare my Mega is on COM4. The above is at the start of my upload but there is a swag of other stuff following. It’s all about comms too. I have seen some post about uploading with Arduino disconnected. Needless to say, I can’t do that…

It’s OK and the panic is over…

I fixed it by plugging the cable into a different USB port. I really don’t know where the problem lies, I have had no reason to suspect the port. I would suggest to anybody who has this problem that they just try another port before getting into anything more complicated

Sometimes it's advisable to clean out the drivers in device manager.

Take a look at 'Error: avrdude' when uploading

it happens to me as well

when i have not defined the port/com

to connect

click where the arow is pointing

once you have clicked there it should look like this:

once your board is plugged in, and no other devises are plugged in, click on any port/com that appears.

define the board.

and upload your code!

hope that fixes your problem

My IDE said Mega was on COM4 and Windows agreed. Windows also said everything is fine. This is not as simple as you seem to think no it is, and what I did to fix it is not necessarily the solution for everybody.