Arduino Pro Micro (ATMega32u4) with Bluetooth HC-05

Only a brief test with the code below, it works perfectly.

Upon receiving “a”, the LED is turned on.

But this only works if you are with IDE Arduino open. If closed, or only with the powered circuit can connect through the phone, but does not seem to correctly recognize the commands. :roll:

what am I doing wrong :?:

*Through AT commands, baud is set to 38400.

char aux = 0;
int led = 17;
void setup() {
  Serial1.begin(38400);
  while (!Serial1);
  pinMode(led, OUTPUT);
  digitalWrite(led, HIGH);
}
void loop() {
  if (Serial1.available()) {
    aux = (char) Serial1.read();
    delay(100);   
    if (aux == 'a') {
      digitalWrite(led, LOW);
    } else {
      digitalWrite(led, HIGH);
    }
  }
  delay(100);
}