Go Down

Topic: Hc05 pairing (AT Mode) (Read 852 times) previous topic - next topic

vishruth_kumar

Mar 20, 2017, 07:30 pm Last Edit: Mar 20, 2017, 07:36 pm by vishruth_kumar
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

Nick_Pyner

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.

terryking228

Hi,
See THIS Page and follow to a utility to check out the HC05
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

vishruth_kumar

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?

Nick_Pyner

#4
Mar 21, 2017, 03:39 pm Last Edit: Mar 21, 2017, 03:40 pm by Nick_Pyner
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.

vishruth_kumar

#5
Mar 23, 2017, 06:26 pm Last Edit: Mar 31, 2017, 04:05 pm by vishruth_kumar
After uploading the empty sketch I am getting no response in my serial monitor. So I followed the this tutorial

http://howtomechatronics.com/tutorials/arduino/how-to-configure-pair-two-hc-05-bluetooth-module-master-slave-commands/

For Slave module I uplaoded the code as:
Code: [Select]
#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:

Code: [Select]
#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:
Code: [Select]
#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




vishruth_kumar

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!

Nick_Pyner

By
Quote
AT+UART?
->+UART(9600,0,0)
and later
Quote
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
Code: [Select]
  BTSerial.begin(38400); in both master and slave programmes? You might try changing it to 9600.

vishruth_kumar

Done sir ! Thank you , It's working

Go Up