Question

I am using an HC_05 Bluetooth module and an Arduino Uno to try and set up a simple bluetooth connection with my Windows Phone (HTC 8X). I am following the online tutorial here.

When I go into settings, my phone sees the "HC_05" bluetooth signal. I click on it, and it connects right away. It stays connected for 5-10 seconds, then suddenly disconnects.

I am thinking that my phone is not receiving any data from the bluetooth module, and thus deciding that the signal is worthless, and dropping it. But even if that, why? When I call btSerial.read() from the linked code, isn't that talking to the device?

The Arduino Code:

#include <SoftwareSerial.h>

const int TX_BT = 10;
const int RX_BT = 11;

SoftwareSerial btSerial(TX_BT, RX_BT);

//Frequency to send periodic messages to Windows Phone, in milliseconds.
//Core code.
const unsigned long periodicMessageFrequency = 5000;
unsigned long time = 0;

//Process the incoming command from Windows Phone.
//It should be changed according to what you want to do.
void processCommand(char* command) {
}

//Send a message back to the Windows Phone.
//Is can't be changed.
void sendMessage(char* message) {
  int messageLen = strlen(message);
  if(messageLen < 256) {  
    btSerial.write(messageLen);
    btSerial.print(message);
  }
}

//Send a set of periodic messages to the Windows Phone.
//It should be changed according to what you want to do.
//This message could be a sensor data, like a thermometer data.
void sendPeriodicMessages() {
}

//Setup Arduino function
void setup() {
  Serial.begin(9600);
  Serial.println("USB Connected");
  btSerial.begin(9600);
}

//Loop Arduino function
//It can't be changed
void loop() {
  if(btSerial.available()) {
      int commandSize = (int)btSerial.read();
      char command[commandSize];
      int commandPos = 0;
      while(commandPos < commandSize) {
        if(btSerial.available()) {
          command[commandPos] = (char)btSerial.read();
          commandPos++;
        }
      }
      command[commandPos] = 0;
      processCommand(command);
  }
  unsigned long currentTime = millis();
  if((currentTime - time) > periodicMessageFrequency) {
    sendPeriodicMessages();
    time = currentTime;
  }
}

The HC_05 is connected as follows:

GND -> GND
3.3V -> 3.3V
RX -> D11
TX-> D10

No correct solution

OTHER TIPS

You connect the HC-05 with the Arduino directly with the Tx-Rx line. HC-05 is supposed to be driven on 3.3v and not 5 volts. Your Arduino Tx pin will supply 5v signal on the HC-05's Rx line which is above the recommneded level. Try putting a voltage converter between the Arduino Tx pin (5v) and HC-05 Rx pin(3.3v).

Maybe there is internally a protection that resets the microcontroller inside HC-05 when voltage goes above 3.3.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top