user-1: My Arduino Leonardo was working properly but for the last two hours when I connect it to a PC via a USB cable, it is reporting something like USB is not recognized and even in device manager it is not showing. However, when I press the restart button on the Arduino, the PC will detect it as an Arduino Leonardo bootloader(com 7) but after few seconds it disappears. What do I have to do? I tried to restart the PC, changed USB cable but the same issue occurs. I checked the USB by connecting another device - it works fine but the Arduino is not recognised.
I tried other PCs also but the same problem continued. What do I have to do?

user10794: It is highly likely that the sketch you loaded is causing this.

However, when I press the restart button on the Arduino, the PC will detect it as an Arduino Leonardo bootloader(com 7) but after few seconds it disappears.

For a few seconds after reset the bootloader will configure the board as a USB serial device, awaiting upload of a new sketch. Once that times out it runs the existing code. If the existing code does not configure the USB port (eg. by doing Serial.begin) then it will cease to enumerate as a USB device. This is perfectly normal.
The "fix" is to upload a sketch that uses the USB interface. For example, open a serial port, open the keyboard (Keyboard.begin()) or similar.

user14693: Nick Gammon's solution worked for me. I am adding the arduino code I used below. 
While Arduino Leonardo is connected to your computer, press its reset button. A COM for Arduino Leonardo appears under the Arduino IDE: Tools > Port: 
You should upload the code within a few seconds just after you press the reset button while the Leonardo COM is appearing. 
The following is the code I used: 
// Start of Code 

void setup() {
  // make pin 2 an input and turn on the
  // pullup resistor so it goes high unless
  // connected to ground:
  Serial.begin(9600);
  pinMode(13,OUTPUT);
  digitalWrite(13,HIGH);
  pinMode(2, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  //if the button is pressed
  if(digitalRead(2)==LOW){
    //Send the message
    Keyboard.print("Hello!");
  }
  delay(1000);
  digitalWrite(13,HIGH);
  delay(1000);
  digitalWrite(13,LOW);
}

// End of Code 


-1: <p>My Arduino Leonardo was working properly but for the last two hours when I connect it to a PC via a USB cable, it is reporting something like <code>USB is not recognized</code> and even in device manager it is not showing. However, when I press the restart button on the Arduino, the PC will detect it as an <code>Arduino Leonardo bootloader(com 7)</code> but after few seconds it disappears. What do I have to do? I tried to restart the PC, changed USB cable but the same issue occurs. I checked the USB by connecting another device - it works fine but the Arduino is not recognised.
I tried other PCs also but the same problem continued. What do I have to do?</p>
 10794: <p>It is highly likely that the sketch you loaded is causing this.</p>

<blockquote>
  <p>However, when I press the restart button on the Arduino, the PC will detect it as an Arduino Leonardo bootloader(com 7) but after few seconds it disappears.</p>
</blockquote>

<p>For a few seconds after reset the bootloader will configure the board as a USB serial device, awaiting upload of a new sketch. Once that times out it runs the existing code. If the existing code does not configure the USB port (eg. by doing <code>Serial.begin</code>) then it will cease to enumerate as a USB device. This is perfectly normal.</p>

<p>The "fix" is to upload a sketch that uses the USB interface. For example, open a serial port, open the keyboard (<code>Keyboard.begin()</code>) or similar.</p>
 14693: <p>Nick Gammon's solution worked for me. I am adding the arduino code I used below. </p>

<p>While Arduino Leonardo is connected to your computer, press its reset button. A COM for Arduino Leonardo appears under the Arduino IDE: Tools > Port: 
<strong>You should upload the code within a few seconds just after you press the reset button while the Leonardo COM is appearing.</strong> </p>

<p>The following is the code I used: </p>

<pre><code>// Start of Code 

void setup() {
  // make pin 2 an input and turn on the
  // pullup resistor so it goes high unless
  // connected to ground:
  Serial.begin(9600);
  pinMode(13,OUTPUT);
  digitalWrite(13,HIGH);
  pinMode(2, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  //if the button is pressed
  if(digitalRead(2)==LOW){
    //Send the message
    Keyboard.print("Hello!");
  }
  delay(1000);
  digitalWrite(13,HIGH);
  delay(1000);
  digitalWrite(13,LOW);
}

// End of Code 
</code></pre>
