Why does my HC-05 Bluetooth module only work when I don’t use Serial.begin()? (Arduino Mega)

Hey everyone,

I’m using an Arduino Mega and an HC-05 Bluetooth module to receive simple characters like 'F' from an Android app (RC Bluetooth Controller). It works only if I don’t include Serial.begin() in my code.

As soon as I add Serial.begin(9600);, the Bluetooth connection seems to stop working — nothing shows up in the Serial Monitor anymore, and no commands are received.

But if I remove Serial.begin(), I start seeing the characters just fine.

Any idea what’s going on here? Why does Serial.begin() break my HC-05 communication?

Thanks in advance!

code:

int EneblePin1 = 26;
int ControlPin1 = 24;
int ControlPin2 = 22;
int val;

void setup() 
{  
  pinMode(ControlPin1, OUTPUT);
  pinMode(ControlPin2, OUTPUT); 
  pinMode(EneblePin1, OUTPUT);  
  Serial.begin(9600);
}

void loop()
{

  while (Serial.available() > 0)
  {
    val = Serial.read();
  }
  if( val == 'F')
    {
      digitalWrite(EneblePin1, HIGH);
      digitalWrite(ControlPin1, LOW);
      digitalWrite(ControlPin2, HIGH);

    }
    else if(val == 'f')
    {
      digitalWrite(EneblePin1, LOW);
      digitalWrite(ControlPin1, LOW);
      digitalWrite(ControlPin2, LOW);
    }  
    else if(val == 'B')
    {
      digitalWrite(EneblePin1, HIGH);
      digitalWrite(ControlPin1, HIGH);
      digitalWrite(ControlPin2, LOW);
    }
    else if(val == 'b')
    {
      digitalWrite(EneblePin1, LOW);
      digitalWrite(ControlPin1, LOW);
      digitalWrite(ControlPin2, LOW);
    }    
}

cuircuit:

A better question might be "why are you hooking your bluetooth module up to Serial and still expecting to be able to use that same object with the Serial Monitor when the Mega has 3 additional SerialX ports that you could be hooking your module up to without interfering with the uploading and monitoring duties that the pins used by Serial have"?

Thank you, that clarifies things for me!
Due to the digital pin limitation of Uno, I recently purchased a Mega. I got used to the Serial interface on Uno.
I didn't realize using the main Serial port with the HC-05 could conflict with the Serial Monitor output window.
I will try the Serial1 interface and relocate the HC-05 to connectors 18 and 19.
Thank you for the answer.

There is a built-in multi-serial example in the IDE.
The RX pin of the BT module should have a voltage divider (1k:2k2) level shifter.
Leo..

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.