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.

what am I doing wrong? :frowning:

*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);
}

Skip the

while (!Serial1);

It is only needed if you are using Serial in the IDE monitor.

Removed.
And simplify void loop, to see the return.

void loop() {
  if (Serial1.available()) {
    Serial1.write((char)Serial1.read()); 
  }
}

I noticed the following:

If the IDE is open, I get the return correctly.

But if the IDE is closed, I receive the return, but as an unknown character, as if the baud was wrong, understand?

How are you viewing the output from Serial1 and what is sending data to it?

When the IDE is closed, what happens if you disconnect and recnnect power to the ProMicro to force it to reset? Note that the 32U4 based Arduinos do not reset in the same way as an Uno or Mega.

...R

Robin2:
How are you viewing the output from Serial1 and what is sending data to it?

When the IDE is closed, what happens if you disconnect and recnnect power to the ProMicro to force it to reset? Note that the 32U4 based Arduinos do not reset in the same way as an Uno or Mega.

...R

Really ... What happened is that on it simply did not start.
Then I put a RST button to the ground. Thus, pressing the button starts perfectly, and all is well.

Is correct that? I tested several times, and everything is OK now.