Problem uploading to board

I wrote the following code and compiled it. It compiled perfectly. But when I tried to upload it, it shows error. I’m using arduino Uno. The code is

#include <Wire.h>
#include <SoftwareSerial.h>
String apiKey = "CTYFS8T04HLD2CCZ";

const int  Up_buttonPin   = 7;    // the pin that the pushbutton is attached to

const int  Down_buttonPin = 8;
SoftwareSerial ser(2, 3); // RX, TX
int total;
int buzzer = 13; 
int data = 0;
int rem;
int buttonPushCounter = 0;    // counter for the number of button presses
int up_buttonState = 0;       // current state of the up button
int up_lastButtonState = 0;   // previous state of the up button

int down_buttonState = 0;         // current state of the up button
int down_lastButtonState = 0;     // previous state of the up button
bool bPress = false;

void checkUp()
{
  up_buttonState = digitalRead(Up_buttonPin);
  if (up_buttonState != up_lastButtonState)    // compare the buttonState to its previous state
  {
    if (up_buttonState == LOW)   // if the state has changed, increment the counter
    {
      bPress = true;  // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter);
    }
    else {
      Serial.println("off"); // if the current state is LOW then the button went from on to off:
    }
    delay(50);  // Delay a little bit to avoid bouncing
  }

  up_lastButtonState = up_buttonState;   // save the current state as the last state, for next time through the loop
}

void alarm()
{ 
  rem = total - buttonPushCounter;
   if(rem<5 && rem>0){
    Serial.println("oshud kinen");
    tone(13, 450);
    delay (500);
    noTone(13);
    delay (500);
   }
} 


void setup(){
  ser.begin(9600);
    Serial.begin(9600);
    pinMode( Up_buttonPin , INPUT_PULLUP);
  pinMode( Down_buttonPin , INPUT_PULLUP);  
    unsigned char check_connection=0;
    unsigned char times_check=0;
    Serial.println("Connecting to Wifi");
  while(check_connection==0)
  {
   Serial.print("..");
   ser.print("AT+CWJAP=\"SSID\",\"PASSWORD\"\r\n");
   ser.setTimeout(5000);
   if(ser.find("WIFI CONNECTED\r\n")==1 )
   {
   Serial.println("WIFI CONNECTED");
   break;
   }
  times_check++;
   if(times_check>3) 
   {
    times_check=0;
    Serial.println("Trying to Reconnect..");
    }
  }
  delay(5000);
}
void loop()
{
    
  if(Serial.available()>0)
  {
    data=Serial.parseInt(SKIP_WHITESPACE);
    total = data;
    Serial.print("total no. of pills: ");
    Serial.println(total);
    while (Serial.available() > 0) {
       Serial.read();
}

  checkUp();
  alarm();

if ( bPress)
  {
    bPress = false;
    ;
  }
  //DHT.read11(DHT11_PIN);
  //humi=DHT.humidity;
  //temp=DHT.temperature;
  Serial.print("total no of pills:");
  Serial.print(total);
  Serial.print("\nNo. of pills taken");
  Serial.print(buttonPushCounter);
  
  // TCP connection
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += "184.106.153.149"; // api.thingspeak.com
  cmd += "\",80";
  ser.println(cmd);
  if(ser.find("Error")){
    Serial.println("AT+CIPSTART error");
    return;
  }
  // prepare GET string
  String getStr = "GET /update?api_key=";
  getStr += apiKey;
  getStr +="&field1=";
  getStr += String(10);
  getStr +="&field2=";
  getStr += String(10);
  getStr += "\r\n\r\n";

  // send data length
  cmd = "AT+CIPSEND=";
  cmd += String(getStr.length());
  ser.println(cmd);

  if(ser.find(">")){
    ser.print(getStr);
    Serial.println(getStr);
  }
  else{
    ser.println("AT+CIPCLOSE");
    Serial.println("CIPCLOSE");
  }
    
  // thingspeak needs 15 sec delay between updates
 delay(16000);  
}
}

The errors are

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xae
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xae
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xae
avrdude: stk500_recv(): programmer is not responding
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xae
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xae
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xae
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xae
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xae
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xae
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xae

Do you have the correct COM port selected in the IDE (Tools->Port->....)?

This one happens to me all the time too.

You also want to check to make sure you have the correct board selected! If you're using the Mega, then choose the mega at Tools --> Board

blh64:
Do you have the correct COM port selected in the IDE (Tools->Port->....)?

Yes. I have noticed one thing. I have a nodemcu connected to my arduino. Whenever I unplug the nodemcu, there are no difficulties with uploading the code. But, if the nodemcu remains connected, the code doesn't get uploaded.

Is it connected to pins 0 and/or 1? Those pins are also used for communication with your computer, including uploads, so connecting anything to those pins can interfere with uploading.

JohnRobert12:

"I'm using arduino Uno."

Powered by the USB cable?