HC-06 with Arduino mega 2560

Hello, I am currently using the arduino mega 2560 with an HC-06. I am also using an app on my smartphone(android). The problem that I have is that my Arduino Mega is not recieving anything, the leds of the tx/rx are also not going on on the Arduino Mega.

My MIT inventor app code:


My schematic:

My code:


#include <SoftwareSerial.h>

SoftwareSerial mySerial(18, 19); // RX, TX
char Message;
void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

void loop() {

  if (Serial1.available() > 0) {
    Message = Serial1.read();
    Serial.println(Message);
  }
}

I hope that somebody can help me

Don't use software serial. the mega has four hw ports.
Run the baud rates up to 115200.

So no sofwtareSerial and just run it on 115200 baud rate?

Yes, use SERIAL1 hw port directly.
Run the baud rates up as far as possible consistent with the far end's capability is a general note.

When you have worked out the issues with the Mega and changed to one of the additional hardware serial instances, it would be best to validate the setup with a well used and well tested commercial phone app rather than your app inventor code. That way, potential issues with the sending code can be separated from issues with the receiving code.

I recommend Kai Morich's Serial Bluetooth Terminal.

1 Like

My app works on the arduino uno with the HC-06, but not on my arduino Mega

Where is Serial1.begin()?

Do not use SoftwareSerial on the Mega.

should I just connect my rx, and tx to pins 1 and 0 or not?

TX on the HC-06 goes to RX1 on the Mega, RX to TX1, with logic level shifters between.

You must use logic level converters to interface 3.3V and 5V components, or you will damage them. I recommend this one: https://www.sparkfun.com/products/12009

It has to be configured for that though.
("Factory" - they are 9600.)

can I also use a voltage devider?

You can try it. 115k is pretty fast though.

A voltage divider is fine, it has nothing to do with the baud rate. You have to configure Bluetooth to run at 115200, if that is what you want, but you might as well stick with 9600 for now.

A voltage divider rounds off transition edges and may not work at 115200 Baud.

Never had a problem at 115200. All my Blueteeth run at that rate. I've never heard of anybody else having a problem either. If it was a problem, it would probably have come up by now. Similarly, while only a fool would say don't bother with it, I have never heard of anybody actually frying their Bluetooth for absence of the divider, so I hope OP didn't panic too much.

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