Cannot upload certain programs to my Arduino Nano [solved]

Hi all,

I have a strange issue in which the error message avrdude: ser_open(): can't open device "\\.\COM4": Access is denied. appears when I try to upload certain programs to my Arduino Nano. This seems to occur for programs that involve some math operations

My Arduino Nano seems to be functional since I was able to upload programs about blinking LEDs and displays to the board without needing to pull out the USB cable. The strange thing is that all the problematic programs work without issues on my Mega 2560 board.

The code posted below is for the KS0033 temperature sensor from Key Studio. The wiring setup is shown in the image above.

void setup() {
  Serial.begin(115200);
  pinMode(A0, INPUT);
}
int reading; 
double f, r, temperature;
String result = "Hello";
void loop() {
  reading = analogRead(A0);
  f = reading*5.0/1023.0;
  r = 4700*(5 - f)/f;
  temperature = 1/(log(r/10000)/3950 + 1/(25 + 273.15)) - 273.15;
  result = String(reading) + String('\t') + String(temperature) + String("°C");
  Serial.println(result);
}

When I try to upload this code to my Arduino Nano, I receive this error message. I will appreciate any help provided for resolving this issue.

Sketch uses 6516 bytes (21%) of program storage space. Maximum is 30720 bytes.
Global variables use 220 bytes (10%) of dynamic memory, leaving 1828 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't open device "\\.\COM3": Access is denied.

Failed uploading: uploading error: exit status 1

Have you by any chance got the Serial monitor open when you try to upload the sketch ?

When I tried uploading the sketch, the serial monitor was closed.

Are you sure that the board is connected to COM3?

I have double checked device manager. It turns out that I was uploading to the incorrect COM port. Thanks for solving my problem!

That does not explain why some sketches could be uploaded and not others

My Arduino Nano was working fine before I encountered this issue. I think that the problem first occurred when I had the serial monitor open since I occasionally open a new sketch in a new window.

It was most likely possible to upload certain sketches since I opened them after closing all instances of the Arduino IDE. At some point while trying the solve the issue, I probably forgot about selecting the correct port since I had tried your suggestions without success.

After some further testing with my Arduino Nano, I suspect that the problem was caused by both an opened serial monitor and incorrect COM port.

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