0

I am using bluetooth hc-05, arduino uno and ap app created by mit app inventor.The problem is myserial.available is returning 0 and hence its loop is not getting executed. I had connected four pins of the hc-05 module. Rx to pin 10, Tx to pin 11, VCC to 5V, GND to GND. On the app it is showing that the mobile is connected to HC-05 however the condition is not met.

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); 

String name="";
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  Serial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.println("Bluetooth is connected");
    name=mySerial.read();
    Serial.println(name);
  }
  else
 {
   Serial.println("Bluetooth is not connected");
  }
}
  • How do you know if you are getting anything out of the HC05? Maybe mySerial.available() is returning 0 because the is nothing there. Do you have a way to check is there is any serial data? Maybe a LED (and resistor) connected between the TX pin and +5 of the HC05. And another concern I have is that the HC05 is a 3.3v device and the TX output might not be high enough. – Rudy Dec 2 '18 at 14:49
  • Are you sure, that the HC-05 is connected to the phone? And have you checked, that the HC-05 actually operates the serial interface at 9600 baud? – chrisl Dec 2 '18 at 14:52
  • 1
    When things don't work it is desirable to break things into smaller pieces in order to determine where the fault may be. Try and have the output of the HC05 feed back into the input of the HC05. So that when you type something on the phone that it will be sent back to the mobile. Removing the Arduino from the equation helps you verify that the HC05 end is working. – Rudy Dec 2 '18 at 21:01
1

I found out my solution. Actually I was connecting Rx to Rx and Tx to Tx.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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