HC-05 HardwareSerial 1, 2, 3 vs SoftwareSerial library

Hi everyone.
I'm a French beginner in Arduino.
I started with Uno but after a while, I needed to use to much sensor and I changed for a Mega.
Recently, I started trying to use a HC-05 module.
Everthing was working fine until these last day.
I didn't get my arduino mega working with SoftwareSerial library.

I followed some tutorial using HardwareSerial pin as Serial1 19/18 - Serial2 17/16 - Serial3 15/14 to declare SoftwareSerial object instance like :

// Rx, Tx
SoftwareSerial mySerial(19, 18);

But it was not working... After some search, I found that it was ussless to do that and better to use directly use Serial1 / Serial2 / Serial3.

And this solution was working...
Then, I tried to use the HC-05 module STATE pin to get the connexion status.

  • First I connected the STATE pin to one empty digital pin as pinMode(state_pin, INPUT). And by this way, I got the status.

  • Then, and maybe I did something wrong at this step (because I didn't find concret example on Internet), and for that I used this example :

http://www.martyncurrey.com/hc-05-fs-040-state-pin/

In that post, it's wrote :

"As a quick visual indicator you can put a LED + suitable resistor on the STATE pin. When the module is connected the LED will light."

I wanted to use a blue LED, but not idea about witch resistor to use... and how really connect the LED to the STATE pin.

I've tried several things :

  • STATE pin to the LED- and LED+ to the arduino pin / STATE pin to the LED+ and LED-. I didn't remember, but in one case I still got the state value by digitalWrite (pin) and in the other case I got no more result... and in both case, the LED was no ligtning.

  • STATE pin to the LED+ and LED- to the arduino GND... still LED no lightning

  • STATE pin to the LED+ <==> LED+ to the arduino pin and LED- ton the arduino GND... still LED no lightning...

But now, I facing a problem. Before start to use the STATE pin, it was working perfectly, I could pair and connect the HC-05 to my android phone and send data from my android phone to the HC-05 module and activate a servo on receiving data...

But since I did my tests with the STATE pin with LED, it doesn't work anymore.
I'm still using HardwareSerial port.
During setup() method, I start serial com with Serial1.begin(9600);
I can get the state status and wait until the module is connected with my phone... but when setup ends and loop starts, the connexion fails and the module is disconnected from my phone and no way to connect them again...

I've tryied with Serial2 and Serial3... It was working one time on Serial3 and after no more. I don't understand... I don't know if I damage something and if the problem comes from the arduino HardwareSerial port or from my HC-05 module

Today I've read on (https://www.arduino.cc/en/Reference/SoftwareSerial) :

"Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69)."

I've tryied with couple of pins 10/11 (in this list) and even with some other pin like 3/4, but I can't get the SoftwareSerial instance working.

In loop, the instance is always not available...

I thougt to try the module on my UNO R3... If I could get it work, I could deduce that the problem comes from my MEGA.

If anybody has an idea to help me, he is welcome...

The first thing to think about is why would you ever want to use software serial on a Mega.

Then, in the highly unlikely event that you must, use the pins recommended, not the hardware serial pins.

Next thing to think about is the purpose of the state pin and why you need to use it. It simply provides an alternative to the State LED on the board and you might suppose that the only time to use it is when you can't see the one already provided. This could happen, but if you are the first person to ever use STATE it wouldn't surprise me.

I've tried with Serial2 and Serial3... It was working one time on Serial3 and after no more. I don't understand... I don't know if I damage something and if the problem comes from the arduino HardwareSerial port or from my HC-05 module

If you have actually damaged something, it is most probably due to user abuse. I don't think it is easy to do any damage to Mega by using the state pin as the bluetooth module has a current limiting resistor parallel to that for the on-board LED. You can probably test the situation by disconnecting the state pin and trying to use the HC-05 in the normal manner.

The first thing to think about is why would you ever want to use software serial on a Mega.

Then, in the highly unlikely event that you must to it, use the pins recommended, not the hardware serial pins.

Because there are many tutorial doing that way... even on Mega. And when you're beginner, you begin following tutorials, and first tuto I followed were doing that.

Next thing to think about is the purpose of the state pin and why you need to use it. It simply provides an alternative to the State LED on the board and you might suppose that the only time to use it is when you can't see the one already provided. This could happen, but if you are the first person to ever use STATE it wouldn't surprise me.

It's exactly what I need, to replace the module onboard small red LED because this one should be hidden in the global device.
If found example using the STATE pin :

I've read somewhere else that to be carefull do not make error with wire and make digitalWrite(pin, HIGH) from arduino pin to HC-05 STATE pin.

If you have actually damaged something, it is most probably due to user abuse.

My module and arduino have less than one mounth... and I work on it around 1h a day...

You can probably test the situation by disconnecting the state pin and trying to use the HC-05 in the normal manner.

Yes, I'm going to retry that next time...

I've re-test :

  • with KEY pin (GND) & STATE pin (A0) disconnected => OK

  • with KEY pin (GND) re-connected = OK

  • with KEY pin (GND) & STATE pin (A0) re-connected = KO

  • with KEY pin (GND) & STATE pin (another analogic pin than A0) re-connected = OK !!!

So, I don't know what's wrong with the A0 pin used as INPUT pin, but it was working and now, it doesn't work anymore, but I use A1, A2, A3... it works fine !

No idea...

Well. hey, do you know that hc05 works in 9600(in some cases) and 38400 baud rate. You should check that first.