Error opening serial port 'COM3'.

I am just learning about getting programs onto an Arduino board and I am getting the above error message. The code is modified from the Blink tutorial sketch:

// declare and assign variable to represent the LED
int led     = 13;
// declare and assign value to the counter
int counter = 0;

// the setup function runs once when you press reset or power the board
void setup() {
  // start Serial
  Serial.begin(9600);
  // initialize digital pin 13 as an output running the LED
  pinMode(led, OUTPUT);
}

// the loop function runs over and over again until 'exit' condition is reached
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(250);              // wait for 2.5 seconds
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(100);              // wait for a second
 
  ++counter; // increment 'counter'
  
  Serial.println(counter);  // print the number of flashes

  if (counter > 19)
  {
    counter = 0;
  }
}

It works okay on one UNO I have, but on another UNO and on a MEGA I get

avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM3
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: ser_open(): can't open device "\\.\COM3": The system cannot find the file specified.



avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
processing.app.SerialException: Error opening serial port 'COM3'.
 at processing.app.Serial.<init>(Serial.java:125)
 at processing.app.Serial.<init>(Serial.java:66)
 at processing.app.SerialMonitor$3.<init>(SerialMonitor.java:93)
 at processing.app.SerialMonitor.open(SerialMonitor.java:93)
 at processing.app.AbstractMonitor.resume(AbstractMonitor.java:110)
 at processing.app.Editor.resumeOrCloseSerialMonitor(Editor.java:2459)
 at processing.app.Editor.access$2900(Editor.java:90)
 at processing.app.Editor$DefaultExportHandler.run(Editor.java:2437)
 at java.lang.Thread.run(Thread.java:745)
Caused by: jssc.SerialPortException: Port name - COM3; Method name - openPort(); Exception type - Port not found.
 at jssc.SerialPort.openPort(SerialPort.java:167)
 at processing.app.Serial.<init>(Serial.java:114)
 ... 8 more
Error opening serial port 'COM3'.

How do I get COM3 open?
Thanks

try this with the ones that don't work:

  • With the Arduino board unplugged from the USB open Tools > Port and note the listed ports.
  • Close the Tools > Port menu.
  • Plug in the USB cable on the Arduino board
  • Wait a bit for the Arduino board to connect
  • Open Tools > Port, the new port on the list is your Arduino board. In some cases it will have the name of the board next to the port name but this doesn't happen with all boards.

If no ports show up on the menu after you plug in the Arduino then you might need to install the driver.

Thanks pert

I don't know what that did but all is working now :) Actually suspect bad connection on USB line :(