Bluetooth paring

Hello, I recently bought ZS-040 HC-06 Bluetooth module, but I went into problem. I cant pair it with my phone. I can comunicate via serial monitor, change boundrate, name, ect, but it just cant connect to phone. It says: HC-06 reject pairing.How can I fix it?

My code:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 2); // RX, TX

String command = ""; // Stores response of the HC-06 Bluetooth device


void setup() {
  // Open serial communications:
  Serial.begin(9600);
  Serial.println("Type AT commands!");
  
  // The HC-06 defaults to 9600 according to the datasheet.
  mySerial.begin(115200);
}

void loop() {
  // Read device output if available.
  if (mySerial.available()) {
    while(mySerial.available()) { // While there is more to be read, keep reading.
      command += (char)mySerial.read();
    }
    
    Serial.println(command);
    command = ""; // No repeats
  }
  
  // Read user input if available.
  if (Serial.available()){
    delay(10); // The delay is necessary to get this working!
    mySerial.write(Serial.read());
  }
}

How can I fix it?

The code you posted allows you to type commands on the PC to configure the bluetooth device.

You need to type the proper commands. We have NO idea what you have done to the bluetooth device.

As stated above, the code is for using Arduino to configure bluetooth rather than talk to the phone. Since you don't know what you are doing, there is a chance you haven't done anything, and it's not a problem. The rejection of pairing may be a different problem altogether, as I believe you should be able to pair with an HC-06 even if you have a configuration programme running.

I therefore suspect you might be trying to pair with an iPhone. IOS will not work with HC-06 and you need to get a Bluetooth 4 module.

Nah Im using HTC ONE M7 phone, simple android. I tried it with BT controlled cars as well, whole tutorial, the only think that I couldnt do is to pair it. May the voltage differences made this problem with RX and TX pins, since I connected them directly to arduino, instead of making it 3.3V ?(tutorial something like this: http://www.instructables.com/id/How-to-control-an-arduino-car-via-Bluetooth-for-be/?ALLSTEPS)

hollowltu:
...the only think that I couldn't do is to pair it.

Nonsense. If you can't pair it, you can't do anything else. Further, the pairing operation is between Android and bluetooth, and the wiring between Bluetooth and Arduino is immaterial. All Arduino does is provide the power. While it is a good idea to provide a voltage divider to Arduino Tx, plenty of people don't and you may not have done any damage.

Your problem may simply be procedural and you might find the following background notes useful

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

starting with understanding the difference between pairing and connecting. Then using some proper code. There should be no need to configure the HC-05, and if you do have the need eventually, there is better code for this than the junk you posted.

Thanks Pyner for your effort. I found out something new, my HC-06 blinks like it is paired or connected (slow blinking once a second instead of 2MHz). As I understood, I should be able to pair even if my code is bad, just I would do anything with it. When I try to pair, I still get HC rejected pairing (instead of allowing me to enter code). I think I will try getting hc05 and get less problems with it.

slow blinking once a second instead of 2MHz

Did you really count all 2 million cycles per second?

Buying an HC-05 is not likely to solve the problem. Reading the notes provided probably will solve the problem, and costs you nothing. I suspect the real problem is that you insist on using the wrong code. The HC-06 is ready to go into AT mode by default so long as it is not connected, and the phone refuses to connect because you are using junk code that sends AT commands.

Dumb mistake by me. I thought I got HC-06 instead of my order they shipped me HM10. A bit changed now :smiley: playing with AT a bit too see configurations, but still cant pair it with my android, without apps on which I can see my hm information (address and so on), but still can`t control it.

Your post is incomprehensible. I don't suppose there is any point in suggesting you try using the module before you start fiddling with it.