[Solved] Bluetooth HC-05 Won't Get Paired To Android

So, recently I follow these series of tutorial How to - Arduino android bluetooth real time graph - YouTube To connect Arduino with Android using Bluetooth module HC-05

I did exactly on his scheme, the bluetooth module detected as HC-05 on my android, but won't get paired.
The red LED keep blinking as Using the HC-06 Bluetooth Module | MCU on Eclipse
said that the red LED on the module indicates the status:
blinking: ready to pair
steady on: paired

here is the code that I should get output "(Paired)" beside my device name

receiver = new BroadcastReceiver(){
            @Override
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if (BluetoothDevice.ACTION_FOUND.equals(action)){
                    BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                    devices.add(device);
                    String s = "";
                    for(int a=0;a<pairedDevices.size();a++){
                        if (device.getName().equals(pairedDevices.get(a))){
                            //append
                            s = "(Paired)";
                            break;
                        }
                    }
                    listAdapter.add(device.getName()+" "+s+" "+"\n"+device.getAddress());

                }else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)){

                }else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)){

                }else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)){
                    if (btAdapter.getState() == btAdapter.STATE_OFF){
                        turnOnBT();
                    }
                }  
            }

        };

instead i got a toast saying that the device is not paired

@Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub
        if (btAdapter.isDiscovering()){
            btAdapter.cancelDiscovery();
        }
        if (listAdapter.getItem(arg2).contains("(Paired)")){

            BluetoothDevice selectedDevice = devices.get(arg2);
            ConnectThread connect = new ConnectThread(selectedDevice);
            connect.start();
        }else {
            Toast.makeText(getApplicationContext(), "device is not paired", 0).show();
        }
    }

here is code arduino side

#define sensor A0

void setup (){
 Serial.begin(115200);
}

void loop(){
  if (Serial.available()>0){
    char re = Serial.read();
  
  switch (re){
    case 'E':
    start();
    break;
  }
  }
}

void start(){
  while(1){
    Serial.print('

what did I miss? note: I am using, external power supply Module HC-05 with two chip (on video there is only one chip) Arduino UNO (on videos used Android Pro Mini));
   Serial.print(floatMap(analogRead(sensor),0,1023,0,5),2);
   delay(10);
   
   if(Serial.available()>0){
     if (Serial.read() == 'Q') return;
   }    
 }
}

float floatMap(float x, float inMin, float inMax, float outMin, float outMax){
 return (x-inMin)*(outMax-outMin)/(inMax-inMin)+outMin;
 
}


what did I miss? note: I am using, external power supply Module HC-05 with two chip (on video there is only one chip) Arduino UNO (on videos used Android Pro Mini)

The tutorial isn't worth watching. I assume your module looks like those in the second link - a plain-vanilla HC-05. The first bit of code should be redundant, the second looks like it is trying to do something else, which might be a problem.

The code below is a bare minimum to prove up the bluetooth - nothing fancy. It will work with a USB connection to the PC without any change. The code you quote may be appropriate for the Pro Mini but this is all you need for the Uno.

Use BlueTerm on the Android. Once you know the code is kosher on the Arduino, all the work is done at the Andoid end. This works on my Android phone and my XP laptop via bluetooth as well as the XP desktop via cable. My ICS tablet can see the Uno, and pair with it, but will not talk to it. This is clearly down to the tablet, and you may have a similar problem. Both phone and tablet use BlueTerm.

void setup()
{
    Serial.begin(9600);
    Serial.println("OK then, you first, say something.....");
    Serial.println("Go on, type something in the space above and hit Send, or just hit the Enter key"); 
}
 
void loop()
{
  while(Serial.available()==0)
  {}
  delay(500);
  Serial.println("I heard you say:      ");
  while(Serial.available()>0)
  {
    Serial.write(Serial.read());// note it is Serial.WRITE
  }
  Serial.println("");
}

I have figured it out anyway, but forget to post the solution here.
we have to pair the device from syste>bluetooth>then input password for the first time then connection paired perfectly.
But, I still got no data stream on app, how should I change the arduino code for the uno? it is seems fine to me.

@nick
thanks, man
Blueterm works great. But seems like the source code is confusing to me, since there are lot of methods involve there. Is there any simple code to buffer the data from serial? or maybe showing it to the view graph directly? it means a lot to me
thx

NB:
at first I got my data on blueterm and now I don't. I didn't make any change on wire scheme. why would this happen?how can i fix this? please help

oneitusatu:
I have figured it out anyway, but forget to post the solution here.
we have to pair the device from syste>bluetooth>then input password for the first time then connection paired perfectly.
But, I still got no data stream on app, how should I change the arduino code for the uno? it is seems fine to me.

@nick
thanks, man
Blueterm works great. But seems like the source code is confusing to me, since there are lot of methods involve there. Is there any simple code to buffer the data from serial? or maybe showing it to the view graph directly? it means a lot to me
thx

NB:
at first I got my data on blueterm and now I don't. I didn't make any change on wire scheme. why would this happen?how can i fix this? please help

If you have been able to get things to work but it no longer does, I'm afraid I can't comment, other than submit it is more likely to be a hardware problem than software. This is not helped by the fact that I don't really understand any of your code, which is the reason why I posted mine. I stress that my comment about the code being appropriate for the Pro Mini is just a guess. The only way I know to have bluetooth work then not, is to leave the USB cable plugged in by accident.

Having said all that and looking at the second block of code, it would appear that the intent is just another datalogging exercise, measuring an analogue sensor on receipt of a signal.

I don't know of any "simple code to buffer the data from serial" but, more importantly, I don't know why you would want to do that either. I just send the stuff out serial.print just like the prints to elsewhere, at one second intervals.

Irrespective of the type of Arduino, I'm sure the principle still holds that you can prove the software is OK by doing it all through the serial monitor, i.e. no bluetooth. Once done, any issues are with the bluetooth module or the terminal.

There is a very promising freebie called bluetooth graphics for Android but I haven't actually used it yet as, I use Excel for that sort of stuff.

I think you are right, nick
At first I'm afraid that this is a kinda hardware issue. But after i restart my phone, my computer, and i try to upload it once again to arduino all system goes well. I don't know why would this happen. Maybe we need to clear the serial terminal or something.

I'm afraid I can't comment further on this - other than that I bet it's something stupid and easily fixed, most probably at the Android end. It probably just needs a fresh pair of eyes.

BTW I have now concluded that Bluetooth Terminal is better than BlueTerm.

BlueTerm has a swag of key configurations, none of which work. Bluetooth Terminal has no configurations, but delivers the goods as it comes out of the box. However, it apppears to have no disconnect command and you have to downwipe the screen to do that.

Nick_Pyner:
I'm afraid I can't comment further on this - other than that I bet it's something stupid and easily fixed, most probably at the Android end. It probably just needs a fresh pair of eyes.

BTW I have now concluded that Bluetooth Terminal is better than BlueTerm.

BlueTerm has a swag of key configurations, none of which work. Bluetooth Terminal has no configurations, but delivers the goods as it comes out of the box. However, it apppears to have no disconnect command and you have to downwipe the screen to do that.

Hi Nick,

I think i need your help, after more than a week I still can't get no data even e bit from this module.
I tried the simplest code from http://english.cxem.net/arduino/arduino5.php, and no data provided by this module.
The text on terminal from arduino could be read on android,but whenever I push button that send 1 or 0 no data received on arduino terminal. I checked with LogCat debug from android it already send the bit.

And I believe that the module baudrate set to 9600, since I got the data from BlueTerm app perfectly.

I tried give a delay both in android and arduino n no result

So how do I checked this module if it's still works? or maybe there's some faulty in my code? I prefer that i missed something important to configure this HC 05

thanks,
Rijdz++++++++

Are you saying you have one way signal Arduino to Android? If so, the baud rate and pairing are OK, and it is fair to assume there is nothing wrong with the module.

I don't know about LogCat, the last thing to worry about is the Android at this stage.

Have you tried the code I posted? It is about as basic as you can get.

If you are using the hardware serial D0,D1. You can prove the code is OK by using serial monitor, bluetooth disconnected, then disconnect USB and try with bluetooth connected.

Nick_Pyner:
Are you saying you have one way signal Arduino to Android? If so, the baud rate and pairing are OK, and it is fair to assume there is nothing wrong with the module.

If you press send on android you should be sure it does send. I don't know about LogCat

Have you tried the code I posted?

If you are using the hardware serial D0,D1. You can prove the code is OK by using serial monitor, bluetooth disconnected, then disconnect USB and try with bluetooth connected.

yeah. it's one way communication, seems like my HC-05 is on slave mode by default, is that possible?
because, i've try to send from blueterm on Android n there's no data received by serial on computer. I'm sure that the sent from my android but I'm not sure that there's data comes out from my bluetooth module.

how do I change this slave mode from HC-05 into master? any recommended link?
thx

[EDITED]
even when this module on a slave mode, it should return the AT command, no?
but why is there no response at all? (I'm already on AT mode where I pulled high the KEY pin first)

oh, your code worked fine as i mention earlier, but when i tried to send from android, no result

oneitusatu:
yeah. it's one way communication, seems like my HC-05 is on slave mode by default, is that possible?

I guess it's possible, but I'm certain it's irrelevant. I have two HC-05s. Due to a comedy of errors, I'm not using them at the moment but they worked as they came out of the box. More to the point, I'm using a HC-06, it is slave only, and does what is supposed to do.

because, i've try to send from blueterm on Android n there's no data received by serial on computer. I'm sure that the sent from my android but I'm not sure that there's data comes out from my bluetooth module.

There are only THREE things that can be wrong with your project -

  1. the hardware
  2. the connections between them
  3. the code.

There quite a lot to suggest that items 1 & 2 are OK but, while the transmit line of your Arduino D1 is OK, maybe D0 isn't i.e. no receive, even though bluetooth is getting it from Android. I'm sure a successful pairing means two way traffic but, as a last resort, you might check the Android is innocent by doing a bluetooth file transfer to PC.

All checked? That leaves the code. I think it's junk. It is surely trying to do more than necessary in order to prove your gear and procedures are kosher. I again suggest you try the code I posted, using D0,D1 in the basic manner. This works the same on serial monitor and bluetooth but, I repeat, not simultaneously.

There quite a lot to suggest that items 1 & 2 are OK but, while the transmit line of your Arduino D1 is OK, maybe D0 isn't i.e. no receive, even though bluetooth is getting it from Android. I'm sure a successful pairing means two way traffic but, as a last resort, you might check the Android is innocent by doing a bluetooth file transfer to PC.

i've also tried with different pin with softwareserial, and no luck to receive incoming data from bluetooth.
here's my setup with arduino and HC-05

HC-05 Arduino

KEY --> Pin9
Rx --> Pin11
Tx --> Pin10
GND --> GND
5V --> 5V

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup()
{
  pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
  digitalWrite(9, HIGH);
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);  // HC-05 default speed in AT command more
}

void loop()
{

  // Keep reading from HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
    Serial.write(BTSerial.read());

  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available())
    BTSerial.write(Serial.read());
}

All checked? That leaves the code. I think it's junk. It is surely trying to do more than necessary in order to prove your gear and procedures are kosher. I again suggest you try the code I posted, using D0,D1 in the basic manner. This works the same on serial monitor and bluetooth but, I repeat, not simultaneously.

what do you mean to check with your code you posted above again? since your code not to try to read the data from bluetooth but just read?
do you mean that i should make program in android itself to try your code to check whether there are communication, no?

[EDITED]
I'm also aware that maybe i had wrong wiring just like the guy in Microcontroller-based switching of AT mode for HC-05 Bluetooth module? - Networking, Protocols, and Devices - Arduino Forum , Nick.
but i've double checked it and it seems fine to me. help

oneitusatu:
i've also tried with different pin with softwareserial, and no luck to receive incoming data from bluetooth.
here's my setup with arduino and HC-05

HC-05 Arduino

KEY --> Pin9
Rx --> Pin11
Tx --> Pin10
GND --> GND
5V --> 5V

OK, to cut through the garbage and address the real problem........

Get of pins 10,11. While it's just a dumb idea now, it's a dumb idea you might regret later, so fix it now.

Connect

HC-05 Arduino

KEY --> nothing
Rx --> Pin D1 (marked Tx) just like God and Arduino intended
Tx --> Pin D0 (marked Rx) ditto
GND --> GND OK
5V --> 5V OK

#include <SoftwareSerial.h>
....................

Forget software serial. You don't need it, so don't use it. You may need it sometime in the future, if so then OK, but, until then, anybody who tells you to use it is just being a smartarse. I might add that anybody who tells you to use software serial on pins 10,11 is an idiot, as well as a smartarse.

what do you mean to check with your code you posted above again? since your code not to try to read the data from bluetooth but just read?

I mean use it. Use it with HC-06 connected to D0,D1, It is a basic test for two way traffic, and all you should need to prove your gear is OK.

do you mean that i should make program in android itself to try your code to check whether there are communication, no?

No. It's Arduino code. Use BlueTerm or whatever you have.

I mean use it. Use it with HC-06 connected to D0,D1, It is a basic test for two way traffic, and all you should need to prove your gear is OK.

yeah it's definitely one way communication, I give up.
I tried with another UNO and still the HC-05 cannot receive any command, maybe there's defect on it's rx pin. I am waiting for another module to check whether the problem still the same. I still believe that there's something important that I missed, not the hardware. And I can't access the osciloscope at the moment.

You said that my module is HC-06? but why my laptop detected HC-05?

My mistake. I realise you use an HC-05, I am currently using an HC-06. The operation for these purposes is the same.

If you have tried the code and connections I posted, you prove the code is kosher by using it with the serial monitor. If no luck, then I guess I have to concede a mechanical defect is possible, maybe bad solder at a pin that is visible and fixable, or the SMD connection to Rx, which I imagine could be tested with a probe.

hi, if u having trouble in making into AT mode of HC-05 (ZS-040)(especiall if one having en/wakeup up pin instead of key pin) and trouble in transfering data between two hc05 module . Follow they bellow procedure
Power off HC-05 module.
Press and hold small button above EN pin.
Power on and keep pressing small button.
Small LED should start to blink slowly about once every 2 seconds.

for more info visit below site:

another good reference for making it into master mode is here:

aftermaking connection if you stuck in transmitting data from one module to another see below:
http://www.martyncurrey.com/connecting-2-arduinos-by-bluetooth-using-a-hc-05-and-a-hc-06-easy-method-using-cmode/