Can anyone help me to solve a problem on unloading to UNO

Hi,

I am a fresher started learning about 4 weeks back, with an Arduino Uno board procured from Amazon, India. I was in the process of trying sketches given in some of the text books I bought from net. I have tried more than 100 simple sketches given in different books.

Everything was fine till today. The last sketch that I tried successfully is pasted below for your reference please.

# include "pitches.h"

int kPinSpeaker = 9;

# define NUM_NOTES 15

const int notes[NUM_NOTES] = {NOTE_C4,NOTE_C4,NOTE_G4,NOTE_G4,NOTE_A4,NOTE_A4,NOTE_G4,NOTE_F4, NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4, NOTE_D4,NOTE_C4,0};// a 0 represents a rest

const int beats[NUM_NOTES] = {1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4};
-const int beat_length = 300;
   
void setup() {
  // put your setup code here, to run once:
pinMode(kPinSpeaker, OUTPUT);
}

void loop() {
  for(int i =0; i<NUM_NOTES; i++){
    if(notes[i] == 0) {
      delay(beats[i] * beat_length); //rest
    }

    else{ourTone(notes[i], beats[1] * beat_length);
    }
//pause between notes
noTone(kPinSpeaker);
delay(beat_length/2);
}
}
void ourTone(int freq,int duration)
{
   tone(kPinSpeaker, freq, duration);
   delay(duration);
}

The above coding worked satisfactorily. The only external hardware connected was a piezo buzzer connected between terminals '9 & 'GND'. After this, when I tried to upload another simple code, I am unable to upload the sketch & am getting an error message, which is copied below. I tried resetting the board several times as well as tried uploading some sketches from the EXAMPLE option under FILE menu, but results are same.

Sketch uses 2,580 bytes (7%) of program storage space. Maximum is 32,256 bytes.
Global variables use 204 bytes (9%) of dynamic memory, leaving 1,844 bytes for local variables. Maximum is 2,048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x71
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x71
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x71
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x71
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x71
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x71
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x71
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x71
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x71
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x71
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

I would be thankful if some of you could help me on this.

Best regards

Anil

Change you USB cable.
Make sure the correct board and com port is selected.
.

Try loop back test.

Is the old sketch still running? If so, does the sketch reset itself when you start trying to upload?

Does disconnecting the buzzer change anything? (I don't imagine it would, though).

It's clearly doing something, since you get the same wrong response each time.
Double-check the board selection in the tools menu (and port selection if you have more than one serial device connected).

And yeah, try loopback test.