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

Blynk not connecting to arduino using hc05 module

After successfully pairing to the hc05 module and connecting to it using the widget, Blynk still says my arduino is offline. why is this happening? And how can i fix it?

Heres what i am using:
Galaxy s8
arduino uno r3
hc-05


    #define BLYNK_USE_DIRECT_CONNECT
    //#define BLYNK_PRINT DebugSerial //for usb connection
    #define BLYNK_PRINT Serial //for hc05 connection
    #include <Servo.h>

    // You could use a spare Hardware Serial on boards that have it (like Mega)
    //#include <SoftwareSerial.h>
    //SoftwareSerial DebugSerial(2, 3); // RX, TX

    //#include <BlynkSimpleStream.h> //for pc connection
    #include <BlynkSimpleSerialBLE.h> //for hc05 connection

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

    //setup data
    int led = 11;           // the PWM pin the LED is attached to
    int brightness = 0;    // how bright the LED is
    int fadeAmount = 5;    // how many points to fade the LED by
    const int trig = 12, echo = 13; //set ultrasonic sensor pins
    long duration, Distanceininch; //Make ultrasonic sensor varables    
    Servo servo1;         //Make servo 1 varable
    Servo servo2;         //Make servo 2 varable

    //Blynk stuff
    BLYNK_READ(V1) {
         //Read ultrasonic sensor
         digitalWrite(trig, HIGH);
         delay(15);
         digitalWrite(trig, LOW);
         duration = pulseIn(echo, HIGH);
         Distanceininch = duration / 148; // time to inches

         Blynk.virtualWrite(V1, Distanceininch); //Send data to blynk app
    }
    BLYNK_READ(V2) {
      int uv = analogRead(A1); //record uv data
      Blynk.virtualWrite(V2, uv); //Send uv data to blynk app
    }

    BLYNK_WRITE(V3) {
     servo1.write(param.asInt());
    }

    BLYNK_WRITE(V4) {
     servo2.write(param.asInt());
    }

    BLYNK_WRITE(V5) {
      digitalWrite(8, HIGH);
      delay(5000);
      digitalWrite(8, LOW);
    }

    BLYNK_WRITE(V6) {
        // set the brightness of pin 11:
        analogWrite(led, brightness);

       // change the brightness for next time through the loop:
        brightness = brightness + fadeAmount;

        // reverse the direction of the fading at the ends of the fade:
        if (brightness <= 0 || brightness >= 255) {
         fadeAmount = -fadeAmount;
       }
       // wait for 30 milliseconds to see the dimming effect
       delay(30);
      analogWrite(led, 0);
    }

    void setup() {

      // declare pin 7 to be an output:
      pinMode(led, OUTPUT);

      //Setup ultrasonic sensor
      pinMode(trig, OUTPUT);
      pinMode(echo, INPUT);

      //attach Servos 1 and 2 to pin 10 and pin 9
      servo1.attach(10); 
      servo2.attach(9); 

      // Debug console
      //DebugSerial.begin(9600);
      //DebugSerial.println("Waiting for connections...");

      // Blynk will work through BTSerial
      // 9600 is for HC-06. For HC-05 default speed is 38400
      // Do not read or write this serial manually in your sketch
      //Serial.begin(9600); //for usb connection
      Serial.begin(115200); //For HC05 connection
      Blynk.begin(Serial, auth);
    }

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

Haven’t used BT myself. Is the project working? I have heard it will still work even showing not connected.

You need to use a seperate “SoftwareSerial” port for the HC-05 as the primary USB/Serial port on an UNO is already used for programming and debug.

PS “paring” is between the module and the phone… but it is your code and serial connection between the module and board that determine the communication success across that pairing.

For example…

https://examples.blynk.cc/?board=Arduino%20Uno&shield=HC05%20or%20HC06&example=GettingStarted%2FBlynkBlink

No, the project does not work
But if i edit the sketch to use usb and run the script on my pc and then make the app use usb then it works

And i tried using softwareSerial and it did not solve the problem
so i just kept the arduino to hc05 connection on pins 1 and 0 to save pins

And how would i check if the serial connection between the module and the board is working?

I tryed putting in my auth key uploading the example and it still said my board is not connected

Have you tried to connect to the board from the bluetooth serial widget’s settings before starting the project? Can you check about screen if it has support for sending logs?

Yes i first pair to the module and then in the app connect to it using the bluettoth widget before pressing the start button

And how would i check if it has support for sending logs?

In the serial consle it says connecting… even after the app says it connected (in the widget)

I know the modules not the problem becuase i tryed using two different hc05 modules and got the same result

I personally never liked using any BT with Blynk as it was so iffy… but…

By following the recommendations :wink: of using SoftwareSerial to allow debugging.

I also recommend you program your module for 9600 Baud.

Then wire and test with simple, working, code.

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

char auth[] = "**********";

SoftwareSerial SerialBLE(2, 3); // RX, TX

void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(9600);  // Debug via Serial Monitor
  SerialBLE.begin(9600);  // BT module
  Serial.println("Waiting for connections...");
  Blynk.begin(SerialBLE, auth);
  Serial.println("Connected");
}

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

BLYNK_WRITE(V0) {
  digitalWrite(13, param.asInt()); // Control the built in LED
}

Use the Serial Monitor in the IDE to confirm connection status…

image

The App should have the BT widget (connected) and a button widget (set to V0 and SWITCH), this will toggle the built in LED on the UNO.

image

It did not blink the internal led when i pressed the button and in the serial consle it still said

13:32:57.391 -> Waiting for connections...
13:32:57.425 -> [0] 
13:32:57.425 ->     ___  __          __
13:32:57.458 ->    / _ )/ /_ _____  / /__
13:32:57.492 ->   / _  / / // / _ \/  '_/
13:32:57.528 ->  /____/_/\_, /_//_/_/\_\
13:32:57.528 ->         /___/ v0.6.1 on Arduino Uno
13:32:57.595 -> 
13:32:57.595 -> [117] Connecting...
13:33:00.583 -> [3195] Login timeout
13:33:02.612 -> [5195] Connecting...
13:33:05.669 -> [8252] Login timeout
13:33:07.671 -> [10252] Connecting...
13:33:10.732 -> [13309] Login timeout
13:33:12.733 -> [15309] Connecting...
13:33:17.796 -> [20367] Connecting...
13:33:22.847 -> [25424] Connecting...
13:33:27.910 -> [30482] Connecting...
13:33:30.968 -> [33539] Login timeout
13:33:32.995 -> [35539] Connecting...
13:33:38.049 -> [40597] Connecting...
13:33:41.099 -> [43654] Login timeout
13:33:43.117 -> [45654] Connecting...
13:33:46.169 -> [48711] Login timeout
13:33:48.159 -> [50711] Connecting...
13:33:51.244 -> [53768] Login timeout
13:33:53.246 -> [55768] Connecting...
13:33:56.277 -> [58825] Login timeout
13:33:58.311 -> [60825] Connecting...
13:34:03.355 -> [65882] Connecting...
13:34:06.409 -> [68939] Login timeout
13:34:08.442 -> [70939] Connecting...
13:34:13.491 -> [75996] Connecting...
13:34:16.555 -> [79053] Login timeout
13:34:18.540 -> [81053] Connecting...
13:34:23.621 -> [86111] Connecting...
13:34:26.674 -> [89168] Login timeout
13:34:28.697 -> [91168] Connecting...

wiat i forgot to reprogram the module to use 9600 baud give me a sec

Ok, i still got the same result

It’s not clear what code you are now running, which advice you’ve taken and which you’ve ignored, what baud rate your HC05 is configured to communicate at, whether you’ve wired your module correctly etc. etc.

I don’t think you’ll get much more constructive advice until you share some of that data.

Pete.

Confirm that you have RX on Arduino going to TX on module and vice versa.

Also, have you tried any NON Blynk code to confirm Arduino to Module connectivity?

my module is now set to 9600 baud and heres the code i am using now

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

char auth[] = "5Q3JV_BBKAKXb-iklQXdvA_QiuAmv-J7";

SoftwareSerial SerialBLE(2, 3); // RX, TX

void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(9600);  // Debug via Serial Monitor
  SerialBLE.begin(9600);  // BT module
  Serial.println("Waiting for connections...");
  Blynk.begin(SerialBLE, auth);
  Serial.println("Connected");
}

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

I also wired the module like you did in the picture (TXD = D2, RXD = D3, GND = GND, VCC = 5V)

i also used some nonBlynk code and it kept printing “11822” instead of “testing…”
I also changed the wiring so it would work with the sketch (TXD = D0, RXD = D1, GND = GND, VCC = 5V)

here is the code

void setup() {
    Serial.begin(9600);
}

void loop() {
  Serial.println('testing...');
  delay(1000);
}

It also did this on my spare hc05 module

Well, if you can manage to program the module’s baud rate, then you should know how to have the proper connection to hardware.

I have just tested a 2nd BT module with my example and it also worked. Perhaps your phone just doesn’t play well with BT? Try other BT apps to confirm.

It is almost impossible to tell what your issue is from here, but I can attest to having many variable results in past with BT in general, let alone with Blynk.