Hc05 pairing (AT Mode)

I am Using arduino UNO and HC05 bluetooth module for bluetooth. Connections are as:

arduino 5v -> 5V of module
arduino 5V -> EN of module
arduino GND -> GND of module
RX of arduino -> RX of module ( through voltage divider)
TX of arduino -> TX of module

Before connecting the module I have uploaded an empty sketch. I have switched on the module by inserting 5v pin and pressing the button on arduino simultaneously. The led on module is blinking with interval of 2 seconds which indicates it is in AT mode.

But when I open the serial monitoring (selecting 38400 baud and Both NC & CR), sending AT should result (OK) but it doesnt show any result. (no response).

According to the tutorial I have followed , I checked for connections but its of no use. Is it the problem with connections or my method?

Thanks in advance

vishruth_kumar:
According to the tutorial I have followed , I checked for connections but its of no use.

No, you haven't, and no, you didn't. The Tx>Rx wiring is the wrong way round. A transmitter transmits to a receiver, not another transmitter. The setting up for AT mode is done with the power cables, which is clearly correct, and the comms connection is not involved.

Hi,
See THIS Page and follow to a utility to check out the HC05

Nick_Pyner:
No, you haven't, and no, you didn't. The Tx>Rx wiring is the wrong way round. A transmitter transmits to a receiver, not another transmitter. The setting up for AT mode is done with the power cables, which is clearly correct, and the comms connection is not involved.

So the correct connection should be:

TX of module -> RX of arduino(through voltage divider)
RX of module -> TX of arduino

Is this connection only for AT Mode? or we have to interchange RX,TX after pairing(Binding the master to slave's address , and assigning master) for my actual program?

No. The divider goes between the 5v the Arduino Tx and the 3.3v bluetooth Rx for obvious reasons, and no, transmitters always transmit to receivers, no matter what.

After uploading the empty sketch I am getting no response in my serial monitor. So I followed the this tutorial

For Slave module I uplaoded the code as:

#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());
}

Connections as :

arduino 5v -> 5V of module
arduino digital 9 -> EN of module
arduino GND -> GND of module
arduino digital 11 -> RX of module
arduino digital 10 -> TX of module ( through voltage divider)

Uploaded the sketch , did the connections and opened the serial monitor after entering in AT MODE:

AT
->OK
AT+UART?
->+UART(9600,0,0)
AT+ROLE?
->+ROLE=0
AT+ADDR?
->+ADDR:98d3:35:cd7d

For master module , uploaded the same code, connected the bluetooth module(same way) ,started the module in AT Mode, opened serial monitor

AT
->OK
AT+UART?
->+UART(9600,0,0)
AT+ROLE?
->+ROLE=0
AT+ROLE=1
->OK
AT+BIND=98d3,35,cd7d
->OK
AT+CMODE=0
->OK

Then I powered down both the arduino started the slave part first and then master. The led in bluetooth module (both master and slave) starts blinking together rapidly 2 times with 2 seconds interval after every 2 blinks. According to me I think the module is paired.

I added a pushbutton to Slave and an led to master.
The code of slave as:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX
int button = 2;
int state = 20;
int buttonState = 0;
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);
  pinMode(button, INPUT);
  Serial.begin(9600); 
  BTSerial.begin(38400);
}
void loop() 
{
 buttonState = digitalRead(button);
 if (buttonState == HIGH) 
 {
   BTSerial.write('1'); // Sends '1' to the master to turn on LED
 }
 else 
 {
   BTSerial.write('0');
 }  
}

The code of master as:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX
int ledPin = 12;
int state = 0;
void setup() 
{
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  Serial.begin(9600);
  BTSerial.begin(38400); 
}
void loop() 
{
 if(BTSerial.available() > 0)
 { // Checks whether data is comming from the serial port
    state = Serial.write(BTSerial.read()); 
 }
 // Controlling the LED
 if (state == '1') 
 {
  digitalWrite(ledPin, HIGH); // LED ON
  state = 0;
 }
 else if (state == '0') 
 {
  digitalWrite(ledPin, LOW); // LED ON
  state = 0;
 }
 delay(10);
}

After uploading the code , the pattern of module led blink shows that it is paired but the master led is not working after pressing the push button. I have been trying all different things but I could not get the output.

Can somebody point out what am I missing..
Please help me out

Thanks in advance

I know its bit too long to read , I have just stated learning arduino and I am unable to find the solution.
Please help me!

By

AT+UART?
->+UART(9600,0,0)

and later

AT+UART?
->+UART(9600,0,0)
AT+ROLE?
->+ROLE=0
AT+ROLE=1

you have specifically checked that bluetooth is running at 9600, and done nothing to change it. So why do you have  BTSerial.begin(38400); in both master and slave programmes? You might try changing it to 9600.

Done sir ! Thank you , It's working

Hello,

I am having problem also with HC-05 module and i have no idea why. I watched several videos and tried following using arduino mega 2560 board:

RX module -> RX arduino pin 0
TX module -> TX arduino pin 1
GND -> GND
VCC -> 5V
EN -> same as VCC

I setup both HC modules, one to slave other to master.. i also set cmode to 0 to only connect to that one address given from other slave module to master. When i try them they both blink twice every 2 second synchronized, this tells me they are paired, Yet they are unable to communicate. BAUD rates are 38400 on both.

What is weird looking for me is the syntax of mac address.
I know that syntax should be like this example: 1234:AA:ABCDEF

Now mine address look like this -> 19:6:ABCDEF....
I am not sure if there are 0 digits and just not shown but this looks weird. Anyway i wasnt successfull yet of making them communicate together..

Did anyone encountered this?

Thank you.

In AT mode the default baud rate is 38400. Unless you change it, the default baud rate in non-AT mode is 9600, You cannot connect the HC05 and serial monitor to the (USB) hardware Serial port at the same time. That is why people use a software serial port for the HC05.

EDIT: Use a different hardware serial port like Wawa says in the next post.

Guttang:
...using arduino mega 2560 board:

RX module -> RX arduino pin 0
TX module -> TX arduino pin 1

Don't.

The Mega has three hardware serial ports (pin 14-19), use one of them.
There is a multiSerial example in the IDE.

Wise to use a level shifter for the RX pin of the BT module, make of a 1k and a 2k (2k2) resistor.
Leo..

Guttang:
I watched several videos and tried following using arduino mega 2560 board:

RX module -> RX arduino pin 0
TX module -> TX arduino pin 1

Clearly not very closely. Connect Tx>Rx and Rx>Tx - for obvious reasons when you think about it. It is OK to use serial pins 0,1 but, ultimately, you will be better off using one of the other ports when using a Mega.

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