Bluetooth communication failure(Arduino mega 2560)

hello!
I connected Arduino Mega 2560 board and Bluetooth hc-05.
At this time, HC-05 was registered as a Bluetooth device in the mobile phone.
However, the Bluetooth Terminal was unable to communicate with the serial monitor.
Why this is happend and how can I fix this?
Thanks :slight_smile:

connection
vcc:5V Grd: ground tx: RX1(19) rx: TX1(18) En:8

This is code.

#define HC05_KEY 8  
#define BT Serial1  

void setup() {
  pinMode(HC05_KEY, OUTPUT); 
  digitalWrite(HC05_KEY, HIGH); 

  Serial.begin(9600);
  BT.begin(9600);  

  Serial.println("Bluetooth module connected...");
}

void loop() {

  if (BT.available()) {
    Serial.write(BT.read());
  }

  if (Serial.available()) {
![Screenshot_20230622-032435_Serial Bluetooth Terminal|243x500](upload://9rWwt5zwBmkXxggBmxerCUBrLZC.jpeg)


    BT.write(Serial.read());
  }
}

Hello note2

Welcome to the worldbest forum.

Try this

Serial.println(BT.read());
BT.println(Serial.read());

hth

Have a nice day and enjoy coding in C++.

1 Like

Is there supposed to be an image?

Is the HC05 EN pin connected to 5V? Is the HC05 RX pin connected directly to the Mega TX pin?
The HC05 inputs are not 5V tolerant and may be damaged by connection to 5V.

pinMode(HC05_KEY, OUTPUT);
digitalWrite(HC05_KEY, HIGH);
For communication mode the EN pin should be LOW or not connected at all.

1 Like

I tried your code (after removing the screen shot) and tried it on my Mega with HC05. My HC05 has a voltage divider on the Mega TX to HC05 RX to drop the Mega 5V to 3.3V for the HC05 and the EN pin is not connected. The code works fine. I type in serial monitor, it shows up in Bluetooth serial terminal and vice versa.


HC05 WIRING

#define HC05_KEY 8
#define BT Serial1

void setup()
{
   pinMode(HC05_KEY, OUTPUT);
   digitalWrite(HC05_KEY, HIGH);

   Serial.begin(9600);
   BT.begin(9600);

   Serial.println("Bluetooth module connected...");
}

void loop()
{
   if (BT.available())
   {
      Serial.write(BT.read());
   }

   if (Serial.available())
   {
      BT.write(Serial.read());
   }
}
1 Like

Thank you very much.
When I did it in the above way, I succeeded in getting the value from the serial monitor to the smartphone.
But Bluetooth to serial monitor communication failed. Is there a solution?

Post photos that clearly shows your wiring, please.

This is wiring.

Wiring looks OK. I don't know why the Mega is not receiving. My Mega receives just fine and transmits just as well with the posted code. The best advice that I can offer, at this point, is to try a different HC05 module.

1 Like

I'll replace the module. :smiling_face_with_tear:
Thank you for your kind advice. :grinning:

You are welcome. I wish that it would have worked better. Good luck.

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