Cant upload sketch shows com port access denied

This is the error message i get. I uploaded sketch twice in the same board this morning but suddenly its not uploading now.

This is the sketch i'm using :


// Define pin connections & motor's steps per revolution
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 6400;
#define M_ZERO 4
#define M_ONE 5
#define M_TWO 6

void setup()
{
  // Declare pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(M_ZERO, OUTPUT);
  pinMode(M_ONE, OUTPUT);
  pinMode(M_TWO, OUTPUT);


  // Here's the pin settings on the DRV8825 that determines the steps and how many steps is in one revolution

  //         M0   M1    M2          RESOLUTION
  //------------------------------------------------
  //        LOW   LOW   LOW        FULL  STEP   1 Revolution  200  steps
  //        HIGH  LOW   LOW        HALF  STEP   1 Revolution  400  steps
  //        LOW   HIGH  LOW        1/4   STEP   1 Rrevolution  800  steps
  //        HIGH  HIGH  LOW        1/8   STEP   1 Rrevolution  1600 steps
  //        LOW   LOW   HIGH       1/16  STEP   1 Revolution  3200 steps
  //        HIGH  LOW   HIGH       1/32  STEP   1 Revolution  6400 steps  1500

  digitalWrite(M_ZERO, HIGH);                        // Lets just start with a base line Full Step
  digitalWrite(M_ONE, HIGH);
  digitalWrite(M_TWO, HIGH);
}
void loop()
{
  // Set motor direction clockwise
  digitalWrite(dirPin, HIGH);

  // Spin motor slowly
  for (int x = 0; x < 30000; x++)
  {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(500);
  }
  delay(1000); // Wait a second

  // Set motor direction counterclockwise
  digitalWrite(dirPin, LOW);

  // Spin motor quickly
  for (int x = 0; x < 30000; x++)
  {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(500);
  }
  delay(1000); // Wait a second
}

Sketch uses 1086 bytes (3%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't open device "\.\COM10": Access is denied.

Problem uploading to board. See https://support.arduino.cc/hc/en-us/sections/360003198300 for suggestions.

In my experience that usually means that another device or program is using the COM port. Does the problem persist if you reboot the PC ?

Take a look at Arduino: How To Fix ser_open(): can't open device - YouTube and also https://support.arduino.cc/hc/en-us/articles/4401874331410--Error-avrdude-when-uploading

I was having a similar issue and for me works reseting the arduino x2. If your arduino doesnt have reset button you can shortcircuit RST pin and GND 2 times and then press upload program in the arduino IDE. You have around 8 seconds starting from the reset to make the upload.