Hc05 disconnecting and not entering AT mode

Hello,

I'm trying to use an hc05 bluetooth module with a mega 2560 so that I can send information to my computer. My computer can see the bluetooth module, but when I try to connect to it, it only works for a couple seconds before disconnecting and then I can't reconnect. I also tried to enter AT mode and the light blinks slowly as expected, but when I try to type commands into the serial monitor, there is no response at any baud rate.

Here's the program I uploaded:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(18, 19); // RX | TX

void setup()
{
  Serial.begin(9600);
  BTSerial.begin(38400);  // HC-05 default speed in AT command more
  Serial.println("Enter AT commands:");
}

void loop()
{

  // Keep reading from HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available()){
    Serial.write(BTSerial.read());
  }

  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available()){
    BTSerial.write(Serial.read());
  }
}

I might have made the level shifter wrong, here's what it looks like:

I've tried a bunch of different tutorials but haven't had any success. any help would be appreciated! Thanks!

First, do you have an Android phone which you can pair with the HC05. Then if you use an app like Kai Morich's Serial BluetoothTerminal can you connect to the module and stay connected?

https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&hl=en_US

What OS do you have on your computer. Do you have a dongle on a serial port, or is the bluetooth built in to the pc?

What procedure did you follow to set up the bluetooth. Do you have a dongle on a serial port, or is the bluetooth built in to the pc?

Connecting and staying connected is independent from communication and the arrangement of the divider.

Sadly I don't have an android phone. My computer uses windows, and bluetooth is built in to it. I have connected a bluetooth headset to my computer before so I don't think it is a problem on the computer's end. I go to settings -> bluetooth and devices -> add device -> bluetooth. The HC05 shows up and I enter the password (1234) The computer says it successfully connects, but right after it shows that it is disconnected and the HC05 blinks rapidly throughout.

You are having a similar experience to the poster in this thread.

See the information in Post #13 and following about the setting up of the Com Port and the use of a terminal program.

Your voltage divider appears to be on Arduino Rx. It should be on Tx.
I believe you have Tx connected to Tx, rather than Tx to Rx. In that event, both issues can be fixed by swapping blue/green at the Arduino end.
Also, you are using software serial on clearly marked hardware serial pins - serial1. Get rid of all references to software serial at once, and use serial1 as serial1.
Your (alleged) successful connection to the PC means nothing as far as Arduino is concerned.

Could you explain more about how to add a com port? I couldn't figure it out. I see a couple com ports and the one that I upload to and I tried to use them with the serial monitor, but nothing happened, so I don't think they were the right ones. I've downloaded coolterm too. Thanks!

thanks for the suggestions! unfortunately they didn't help :frowning:

If what I assume is actually true, you will be well advised to remember them. Your Windows COM port issues rather depend on how Bluetooth is installed, and the onboard software used, hence Cattledog's question. A laptop usually beats a desktop, and Android beats both. You might find more on the Martyn Currey website, and begging, borrowing or stealing an Android phone is a really good idea.

To work on the pc connection issue, you are best to just work with the HC05 module powered by 5v and ground on the Mega. The Mega should be connected to the pc by the USB cable you will use to download code.

You should se a red light flashing rapidly on the HC05.

I have Win11, and I think 10 is similar. What OS do you have?

In the PC settings under Bluetooth and Devices you should use "Add Device", find the HC05 and enter the password. At this point you should see the HC05 paired with the PC, but not connected.

You should be able to click on Devices and find the HC05. Find the More Bluetooth Settings and you should be able to add an outgoing com port to use with the HC05.

You should be able to open that port with the Serial monitor or Cool term, and see the red light on the HC05 change to the connected blink pattern of two quick flashed and a few seconds off.

How far can you get with this process. It was all described in perhaps better detail in the previously linked thread. As @Nick_Pyner says, all this may depends on the PC and the Bluetooth used inside, and the version of Windows.

Now, that's a good idea...

This worked! The hc05 is connected now and blinks correctly. The outgoing COM port is COM6, and there is an ingoing COM port COM7. However, when I try to send text over serial through COM6 on 9600, nothing happens. I checked whether it had any effect on COM7 or on 38400 baud, but the serial monitor doesn't show anything. Do you know why? Also does this mean that the hc05 works correctly (and I'm just misusing it) so I don't need to steal borrow an android phone?

I have a MB102 but the pins are bent and it won't fit into the breadboard so I'll have to wait a couple days before I can power it externally. Thanks again for the helps so far!

puts on ski mask

just curious, why is it that the HC05 would work better on a laptop and best on a phone?

A laptop usually comes with a factory-installed Bluetooth, rather than your plug-in dongle and, if you are lucky, some decent Bluetooth management software. For example, I have never heard of a laptop that uses two COM ports for one Bluetooth. Android phone is even simpler, and more bulletproof.

The "However" might be due to the issues raised in reply #5. Successful connection to PC is no guarantee of kosher connection to Arduino.

Correct blinking may confirm no more than that you have power, and remembered to push the button.

If you wish to use AT mode, no amount of fartarsing with 9600 will get you a result.

Come to think of it, using AT mode is not such a great idea at this stage of proceedings. There is no evidence that you actually need to use it, and plain two-way communications @ 9600 baud would be a better objective.

That's great news. Connected and in communication mode is the necessary starting place.

Now you can move on to communication between the pc and the Mega,

As mentioned earlier, there were several issues with your code and wiring. Can you please post what you currently have.

You should be using Serial1 and not software serial, and Rx and Tx are cross connected to the module, rx>tx and tx>rx.

Do you want to use the Serial monitor in the ide, or a terminal app like cool term to communicate between the pc and the Arduino?

Regarding the Com ports, there will be one com port showing for the mega itself connected to USB, and one com port for the PC bluetooth. You should be able to connect and disconnect by opening and closing the com port that was set up as the Outgoing port on the pc and communicate to the module over that port with either cool term or the ide serial monitor.

here's my setup and code:

5v - vcc
gnd - gnd
tx1 (18) - rx
rx1 (19) - tx

the resistor closer to the camera is 1k and connects 19 to rx, and the other one is 2k and connects to ground..

void setup()
{
  Serial.begin(9600);
  Serial1.begin(38400);  // HC-05 default speed in AT command more
  Serial.println("Enter AT commands:");
}

void loop()
{

  // Keep reading from HC-05 and send to Arduino Serial Monitor
  if (Serial1.available()){
    Serial.write(Serial1.read());
  }

  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available()){
    Serial1.write(Serial.read());
  }
}

I would prefer to use the serial monitor to communicate. I think COM7 may be some other device, COM6 is definitely the one that connects and is outgoing.

ok! I wanted to enter AT mode because some sources online said that problems may be because the hc05 has some settings wrong.

The default baud rate of the HC05 in communication mode is 9600 baud.
Try:

//Serial1.begin(38400);  // HC-05 default speed in AT command more
Serial1.begin(9600);

I would prefer to use the serial monitor to communicate.

You will need to open two separate instances of the IDE.

One will connect to the Serial port used to load the code onto the Mega and will have one monitor window.

The other instance of the ide will have a blank sketch and the Port will be set to the com port of the PC bluetooth. Open the monitor window on that port.

You should be able to enter and read messages on both running monitors.

Nonsense. Probably a forlorn hope from somebody with a dodgy HC-05, of which there are many around. Most Bluetooth users never need AT mode, ever. I believe any suss HC-05 will work just fine if left in its defaults.

Pin 19 is Rx

I changed the Serial1 baud rate to 9600 and opened another serial monitor. The light still flashes correctly, but text I send through com5 doesn't show up on com3. I noticed that when I sent text, the RX light blinked, which I think means that it received the text? Here's the consoles:

(The com port changed from com3 to com6 because it disconnected and then I had to readd the com port and it did it to com3)