Reading Data from Bluetooth using HC-05 Serial

2.5k Views Asked by At

I am having trouble reading data from the bluetooth serial interface on the Arduino.

Here my code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(8, 7); // RX, TX

void setup() {
  mySerial.begin(38400);   
  Serial.begin(38400);
}
String Data = "";
void loop(){
  //mySerial.println("Bluetooth Out");
  
  while(mySerial.available()){
    char character = mySerial.read();
    Data.concat(character);
    if (character == '\n'){
        Serial.print("Received: ");
        Serial.println(Data);
        Data = "";
    }
  }
}

This should take whatever I enter into the bluetooth serial and print it on the regular serial port. Here is what I've tried:

If I uncomment mySerial.println("Bluetooth Out"); then I see the message bring printed out to the bluetooth terminal.

I tried similar to above to print to normal serial out and I see it being printed.

I've tried multiple ways (from some tutorials online) to decode the string and the data coming from mySerial, but nothing is happening.

I am using arduino Serial Monitor to check the ports, however I also tried to use the bluetooth terminal on my laptop and same behavior.

So I guess, what is the proper way for me to read data from the bluetooth serial port?

0

There are 0 best solutions below