Bluetooth HC-06 on Arduino mega serial 1, 2 or 3 not working

Dear Arduino Community,

So I have the following setup:

Arduino mega 2560, connected through usb cable to laptop
HC-06 Bluetooth module (5v compatible)

I want to send commands from a mobile phone through bluetooth to the Arduino.

The whole thing is working when connections are made like this:
(HC-06 | Mega2560)
GND | GND
5v | 5v
TXD | RX0
RXD | TX0

Then I tried running this on the Serial 1 (and 2 and 3). However it ain't working on those other hardware serial ports?

Not working:
(HC-06 | Mega2560)
GND | GND
5v | 5v
TXD | RX1
RXD | TX1

(HC-06 | Mega2560)
GND | GND
5v | 5v
TXD | RX2
RXD | TX2

(HC-06 | Mega2560)
GND | GND
5v | 5v
TXD | RX2
RXD | TX2

The example code I found on the internet that works when I use Serial but not when using Serial1 , Serial2 or Serial3.

int ledPin = 13;  // use the built in LED on pin 13 of the Uno
int state = 0;
int flag = 0;        // make sure that you return the state only once

void setup() {
  // sets the pins as outputs:
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);

  Serial.begin(9600); // Default connection rate for my BT module
  Serial1.begin(9600); // Default connection rate for my BT module

}


void loop() {
  //if some data is sent, read it and save it in the state variable
  if (Serial1.available() > 0) {
    state = Serial1.read();
    flag = 0;
  }
  // if the state is 0 the led will turn off
  if (state == '0') {
    digitalWrite(ledPin, LOW);
    if (flag == 0) {
      Serial1.println("LED: off");
      flag = 1;
    }
  }
  // if the state is 1 the led will turn on
  else if (state == '1') {
    digitalWrite(ledPin, HIGH);
    if (flag == 0) {
      Serial1.println("LED: on");
      flag = 1;
    }
  }


}

Do you guys have any idea how come this program isn't working while I'm using serial 1, 2 or 3 but it does when using the default?
The default port is used for the Touch Screen which I'm also going to be using (but not in this example)

Thanks for your ideas!

I just tried to connect everything another way:

(HC-06 | Mega2560)
GND | GND
5v | 5v
TXD | TX1
RXD | RX1

So tx to tx now (So not tx to rx)

Now it looks like everything is working fine. Could this give any problems maybe?

It should give lots of problems, most likely very soon.

You need to connect Bluetooth Tx to Rx1 and Rx to Tx1 (etc). And use Serial1 to communicate with the Bluetooth device

For test purposes read data from the Bluetooth device and display it on the Serial Monitor,

Use one of the examples in serial input basics to receive data. Obviously change Serial to Serial1 where appropriate.

...R

Hello,

I had the same problem.

Here is how I solved it:

void setup()
{
  pinMode( 19, INPUT_PULLUP ); // fix Serial1
  pinMode( 17, INPUT_PULLUP ); // fix Serial2
  pinMode( 15, INPUT_PULLUP ); // fix Serial3
  ...

I'm almost sure it will work for you too :wink:

guix:

{

pinMode( 19, INPUT_PULLUP ); // fix Serial1
  pinMode( 17, INPUT_PULLUP ); // fix Serial2
  pinMode( 15, INPUT_PULLUP ); // fix Serial3
  ...




I'm almost sure it will work for you too ;)

Yes, I think that has to become standard procedure these days. I don't think it will do any harm if it's redundant.

It's certainly a better idea than this absurd Tx>TX/Rx>Rx

Thanks for your input guys.

I just came to the conclusion that my (clone) board has TX1 on 19 and RX1 on 18

An official board has TX1 on 18 and RX1 on 19. That might be the reason why connecting my RXD from bluetooth to pin 18 might work (since this is acutally TX1 instead of RX1 printed on the board)

Am I correct that my board might have misprinted these values? Is it always 18 for TX and 19 for RX?

prom0:
Am I correct that my board might have misprinted these values?

Who would ever know?

Is it always 18 for TX and 19 for RX?

Very probably.

Ah, I got a clone from "DCcEle" with these marking problems... Also Rx and Tx LEDs are swapped, and some other stupid label mistakes, no "reset-en" track... Might explain why they sell it for less than 10€ :slight_smile:

I guess the problem is solved then :slight_smile: Just connect RXD to 18 and TXD to 19.

I believe the mix up is on the HC-06 module. I have an HC-06 and I have to do the same thing: tx to tx and rx to rx and it has worked fine for me no problem. I also have read this a number of other places but I have never seen an actual explanation. I think you should be fine.