BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Issue with bluetooth connection HC-05


#1

Hello !

I am working on a project where i have to control two led’s and pushbutton . i am not an expert on this topic. i kindly request for some help.

I know for a fact that the below project works but i am having some reliability issues. my phone detects the HC-05 bluetooth module and i go to the blynk app and connect my HC-05 using the bluetooth widget and when i press play button, i see that the frequency of the led blinking on the HC-05 changes only for a few seconds and goes back to its normal frequency and i see that my aurdino Uno in not online yet.

i am able to see that the aurdino connects and is “ready” ,after a few seconds it says login timeout
Capture

when i press the stop button and then visit the bluetooth widget i don’t see my HC-05 connected anymore.

the following is the details of configuration

• Hardware model : aurdino uno R3 + communication type : bluetooth.
• Smartphone OS : Android 7.0 + version : 2.27.1
• Blynk server
• Blynk Library version : 0.5.4
• the code i have been using


#define BLYNK_PRINT Serial
#include <SoftwareSerial.h>
//SoftwareSerial SwSerial(10, 11); // RX, TX
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
char auth[] = "xxxxxxxxxxx";

SoftwareSerial SerialBLE(10, 11); // RX, TX

// Set your LED and physical button pins here
const int ledPin60ml = 2;
const int btnPin60ml = 3;
const int ledPin30ml = 4;
const int btnPin30ml = 5;
const int PCB_60ml_input = 6;
const int PCB_30ml_input = 7;

BlynkTimer timer;
void checkPhysicalButton();

int ledState60ml = LOW;
int btnState60ml = HIGH;
int ledState30ml = LOW;
int btnState30ml = HIGH;

// Every time we connect to the cloud...
BLYNK_CONNECTED()
{
  // Request the latest state from the server
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V4);

  // Alternatively, you could override server state using:
  Blynk.virtualWrite(V2, ledState60ml);
  Blynk.virtualWrite(V4, ledState30ml);
}

// When App button is pushed - switch the state
BLYNK_WRITE(V2)
{
  ledState60ml = param.asInt();
  digitalWrite(ledPin60ml, ledState60ml);
  digitalWrite(PCB_60ml_input, HIGH);
}
BLYNK_WRITE(V4)
{
  ledState30ml = param.asInt();
  digitalWrite(ledPin30ml, ledState30ml);
  digitalWrite(PCB_30ml_input, HIGH);
}

void checkPhysicalButton()
{
  if (digitalRead(btnPin60ml) == HIGH)
  {
    // btnState is used to avoid sequential toggles
    if (btnState60ml != HIGH)
    {
      // Toggle LED state
      ledState60ml = !ledState60ml;
      digitalWrite(ledPin60ml, ledState60ml);
      digitalWrite(PCB_60ml_input, HIGH);

      // Update Button Widget
      Blynk.virtualWrite(V2, ledState60ml);
    }
    btnState60ml = HIGH;
  }
  else
  {
    btnState60ml = LOW;
  }
  if (digitalRead(btnPin30ml) == HIGH)
  {
    // btnState is used to avoid sequential toggles
    if (btnState30ml != HIGH)
    {

      // Toggle LED state
      ledState30ml = !ledState30ml;
      digitalWrite(ledPin30ml, ledState30ml);
      digitalWrite(PCB_30ml_input, HIGH);
      // Update Button Widget
      Blynk.virtualWrite(V4, ledState30ml);
    }
    btnState30ml = HIGH;
  }
  else
  {
    btnState30ml = LOW;
  }
}

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

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

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

  pinMode(ledPin60ml, OUTPUT);
  pinMode(btnPin60ml, INPUT_PULLUP);
  digitalWrite(ledPin60ml, ledState60ml);
  pinMode(ledPin30ml, OUTPUT);
  pinMode(btnPin30ml, INPUT_PULLUP);
  digitalWrite(ledPin30ml, ledState30ml);
  pinMode(PCB_60ml_input, OUTPUT);
  pinMode(PCB_30ml_input, OUTPUT);
  // Setup a function to be called every 100 ms
  timer.setInterval(100L, checkPhysicalButton);
}

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

your help goes a long way, thank you in advance !


#2

Comparing your code with the example that comes with the Blynk library (https://github.com/blynkkk/blynk-library/blob/master/examples/Boards_Bluetooth/Serial_HC05_HC06/Serial_HC05_HC06.ino)
I’m missing the “#define BLYNK_USE_DIRECT_CONNECT” … :wink: