arduinobluetootharduino-uno

Arduino UNO with Bluetooth HC-06 on macbook cannot get data


I using Arduino UNO with HC06 This is my code

include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); 


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

void loop() {
  if (BTSerial.available()) {
    char data = BTSerial.read();
    Serial.print("get data:");
    Serial.println(data);
  }

  if (Serial.available()) {
    char data = Serial.read();
    BTSerial.write(data);
    Serial.print("send data: ");
    Serial.println(data);
  }
}

after I connect it by bluetooth with my macbook pro, I test on serial monitor like figure. It only print the "send data", but no print "get data". I don't know why!

enter image description here


Solution

  • ".available()" function returns true when you have a signal or bytes on RX. You may have no signal or bytes on BTSerial RX pin.