Arduino Leonardo with HC-05

I am having some problem establishing communication between my PC and leonardo via bluetooth.
I understand that leonardo board using Serial1 instead of Serial class.

//Standard PWM DC control
int E1 = 5;     //M1 Speed Control
int E2 = 6;     //M2 Speed Control
int E3 = 11;    //M3 Speed Control
int M1 = 4;     //M1 Direction Control
int M2 = 7;     //M2 Direction Control
int M3 = 9;    //M3 Direction Control

void setup(void) 
{ 
  int i;
  //for(i=4;i<=7;i++)
  Serial.begin(9600);
  Serial1.begin(9600);
  while (!Serial1)
{
    // do nothing
} ;
  Serial1.println("Run keyboard control");
} 
 
void stop()                    //Stop
{
  digitalWrite(E1,LOW);   
  digitalWrite(E2,LOW);
  digitalWrite(E3,LOW);  
}   
void advance(char a,char b,char c)          //Move forward
{
  analogWrite (E1,a);      //PWM Speed Control
  digitalWrite(M1,LOW);    
  analogWrite (E2,b);    
  digitalWrite(M2,LOW);
  analogWrite (E3,c);    
  digitalWrite(M3,LOW);
}  

void back_off (char a,char b,char c)          //Move backward
{
  analogWrite (E1,a);
  digitalWrite(M1,HIGH);
  analogWrite (E2,b);    
  digitalWrite(M2,HIGH);
  analogWrite (E3,c);    
  digitalWrite(M3,LOW);
}

void Left (char a,char b,char c)             //Move Left
{
  analogWrite (E1,a);
  digitalWrite(M1,LOW);    
  analogWrite (E2,b);    
  digitalWrite(M2,HIGH);
  analogWrite (E3,c);    
  digitalWrite(M3,LOW);
}
void Right (char a,char b,char c)             //Move Right
{
  analogWrite (E1,a);
  digitalWrite(M1,HIGH);    
  analogWrite (E2,b);    
  digitalWrite(M2,LOW);
  analogWrite (E3,c);    
  digitalWrite(M3,HIGH);
}

void Turn_R (char a,char b,char c)             //Rotate CW
{
  analogWrite (E1,a);
  digitalWrite(M1,HIGH);    
  analogWrite (E2,b);    
  digitalWrite(M2,LOW);
  analogWrite (E3,c);    
  digitalWrite(M3,LOW);
}

void Turn_L (char a,char b,char c)             //Rotate CCW
{
  analogWrite (E1,a);
  digitalWrite(M1,LOW);    
  analogWrite (E2,b);    
  digitalWrite(M2,HIGH);
  analogWrite (E3,c);    
  digitalWrite(M3,HIGH);
}
 
void loop() 
{
  if(Serial1.available() > 0){
    //Serial.print("Hello");
    char val = Serial.read();
      switch(val)
      {
      case 'w'://Move Forward
        advance (255,255,0);   //move forward in max speed
        break;
      case 's'://Move Backward
        back_off (255,255,0);   //move back in max speed
        break;
      case 'a'://Move Left
        Left (255, 255, 255);
        break;
      case 'd'://Move Right
        Right (255, 255, 255);
        break;
      case 'q'://Rotate CCW
        Turn_L (255, 255, 255);
        break;
      case 'e'://Rotate CW
        Turn_R (255, 255, 255);
        break;
      case 'z':
        Serial1.println("Hello");
        break;
      case 'x':
        stop();
        break;
      }
  }
}

While using USB wire, everything is work well when I input w,a,s,d

But when I connect through bluetooth COM port, nothing happened.

void loop() 
{
  if(Serial1.available() > 0){
    //Serial.print("Hello");
    char val = Serial.read();
      switch(val)

Insted, as you connected the BT to serial1,

use

void loop() 
{
  if(Serial1.available() > 0){
    //Serial.print("Hello");
    char val = Serial1.read();
      switch(val)

Regards, -Malhar

Thank for you reply Malhar.

I have amended the code but somehow it still does not work as expected.

Was wondering if the Vin on the HC05 should be connected to the 5V or the 3V3 on the leonardo board? Does it matter to where it is connected?

Regards,
BK