Bluetooth connection issues

Hello! I am new to Blynk and also in many aspects a beginner regarding Arduino. I am using an Arduino Mega 2560 and I am trying to connect my Bluetooth HC-06 with my Android Smartphone (Android Version 9). I am not using a local server and the Blynk library version is 0.6.1.
However, there seems to be some problem with the connection. I know that the Bluetooth module itsself works, because I have used it with another app in order to test that aspect. The code I implemented is the example code “Serial_HC05_HC06.ino” with the respective Token as well as RX/TX pins. When I try to connect the phone to the module in the Bluetooth Widget, the device appears and I am able to select connect. After that it also appears as connected as long as I stay in the widget. If I exit it and enter the widget again, it disappears. The lights on the module also do not stop blinking and the device does not seem to be connected although it said so before in the widget itself. Thus I am not able to connect the device when I start the application. I also tried to restart my phone and tried different versions of code, but nothing worked. Is there a solution to this? I tried to find a similar question here in the community, I may have overlooked it.
I’m sorry if the solution is obvious, but like I stated above I am new to Blynk. Thank you for reading!

Update to the issue: I am now using this code (it still doesn’t work):

#define BLYNK_PRINT Serial
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "(here is my Token)";

SoftwareSerial SerialBLE(10,11);

void setup()
{
  // Debug console
  Serial.begin(9600);

  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

  Serial.println("Waiting for connections...");
}

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

And the serial monitor shows this error:
Blynk

Your Mega has three serial ports. Why are you using Software Serial to create another ‘virtual’ serial port?

Pete.

I didn’t know how to, so it seemed easier to just create another serial port like in the examples. I changed it now. Thanks for the tip! :slight_smile: However, the problem is still there…

So how exactly is your HC-06 connected now, and what code are you using?
Is the problem solved?
Does your phone have a connection to the internet?

Pete.

Unfortunatly, the problem isn’t solved. My HC-06 is connected through the third serial port on the device. I tested the module and the wiring with another app, the problem does not seem to come from these aspects. Also, my phone is connected to the internet. This is the code (it’s only the example code from Blynk, I did not implement anything else):

#define BLYNK_PRINT Serial
#include <BlynkSimpleSerialBLE.h>
char auth[] = "(Here is my Token)";

void setup()
{
  Serial.begin(9600);
  Serial3.begin(9600);
  Blynk.begin(Serial3, auth);
  Serial.println("Waiting for connections...");
}

void loop()
{
  Blynk.run();
}

What code were you running on the Mega when you did this?
Are you sure your HC-06 is operating at 9600?

What are you seeing in the Bluetooth widget in the app, are you sure you’re connecting to the correct Bluetooth device from the widget?

Pete.

I used this code as a test to switch a LED on/off:

char input;
void setup() {
  Serial.begin(9600);
  Serial3.begin(9600);
  pinMode (5, OUTPUT); 
}

void loop() {
  if (Serial3.available()) {
      input = Serial3.read();
      if(input == '1'){
        digitalWrite(5, HIGH);
      }
      if(input == '0'){
        digitalWrite(5, LOW);
      }
  }
}

I did not change the baud rate manually, so it should be set to default. I tried to use AT-commands in order to check the rate. Somehow I can change the name of the device, but the other commands do not work. But if the code above works, 9600 should be right, or is there still a possibility that the module works at a different rate?

Regarding the Bluetooth widget: I set the name manually to “Arduino”, so I am sure that it is the right device. I’ll add some pictures in the following. If I click on the widget before starting the application on my smartphone (but having uploaded the code on the Arduino) and click connect, it appears as connected:

If I exit the widget and re-enter it, it disappears:

If I start the application on the phone and then try to connect the device, sometimes it says this:

… but sometimes it does connect and the serial monitor shows this: [63603] Ready (ping: 706ms).
Also, the lights on the HC-06 stop blinking. So, the module acts like it is connected. However, if I exit the widget, the device appears as offline and if I re-enter the widget, it also does not appear as connected. Additionally, the serial monitor shows the login timeout error again.