2

I am trying to both send and receive data using bluetooth module.

Receiving data works fine with this code:

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

void loop() { 
    if (Serial1.available()) {
        Serial.println(Serial1.read());
    }

    delay(20);                          
}

But I cannot send any data. This is what I am doing:

void loop() { 
    if (Serial1.available()) {
       Serial.println(Serial1.read());
    }

    delay(20);

    if (digitalRead(bluetoothInput) == HIGH) {
        Serial1.write("2");
        // only "send" prints. Nothing in android terminal
        Serial.println("send!");
        delay(1000);
    }

    delay(20);                            
}

What am I doing wrong?

I am using Arduino Leonardo and Bluetooth terminal app on Android device.

4
  • Are you actually using softwareserial? On the leonardo you are probably using the hardware UART, so you should remove that tag. In terms of your problem, have you received any data? If it is failing in both directions you likely have not paired the devices, have the baud rate misconfigured or your Android app is broken. Aug 7, 2016 at 17:47
  • As I wrote receiving data works fine. I cannot only send data from arduino. And I've deleted the tag. Thanks for noticing. Aug 7, 2016 at 17:56
  • Do you have BT module with 5V to 3.3V level shifter? Does BT module works if you wire it as loopback (tx pin connected to rx pin without arduino)?
    – KIIV
    Aug 7, 2016 at 18:13
  • I've tried connecting it as loopback but it doesn't work either. My module is Sparkfun mate gold Aug 8, 2016 at 14:43

1 Answer 1

2

I've found the problem

It should be:

Serial1.println("2");

instead of:

Serial1.write("2");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.