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();
}
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.
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?
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.
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)
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.