Bluetooth HC-05 hasn't received data

I have 2 HC-05 modules connected with 2 UNO, one is in master role and the other slave, now I click the button on master, I could read the value altering in Serial Monitor, and the 2 HC-05 were paired - the led blinking in about 2Hz every 5 seconds, while the slave value of led State didn't changed(I have shifted PORT so as to Serial Monitor),

could anyone tell me if there's error in the code:

the Master:

// Basic Bluetooth sketch HC-05_master_38400
// Connect the HC-05 module and communicate using the serial monitor(baud rate: 9600)
//
// The HC-05 defaults to commincation mode when first powered on.
// to be placed into AT mode by pushdown and holding the "EN" button when power-on if needed.
// the default baud rate for communication mode is 38400(master - slave)
// the defualt role of HC-05 is slave.
//
//
//  Pins
//  BT VCC to Arduino 5V out. 
//  BT GND to GND
//  BT RX to Arduino pin 13 (through a 1117 3.3v regulator)
//  BT TX to Arduino pin 12 (no need voltage divider)
//
// LED(via 1.5kΩ) - D8
// Button(pull-up to 5v) - D7
 
 
#include <SoftwareSerial.h>
SoftwareSerial BTserial(12, 13); // RX | TX
// Connect the HC-05 TX to Arduino pin 12 RX. 
// Connect the HC-05 RX to Arduino pin 13 TX through a voltage divider.

const byte ledPin = 8;
const byte buttonPin = 7;

bool ledState = false;
bool buttonState = HIGH;
 
//char c = ' ';
 
void setup() 
{
    // start th serial communication with the host computer
    Serial.begin(9600);
    Serial.println("Arduino with HC-05 is ready");
 
    // start communication with the HC-05 using 38400
    BTserial.begin(38400);  
    Serial.println("BTserial started at 38400");

    pinMode(ledPin, OUTPUT);
    pinMode(buttonPin, INPUT);
}
 
void loop()
{
  ledState = digitalRead(ledPin);
  buttonState = digitalRead(buttonPin);

  Serial.print("buttonState = ");
  Serial.println(buttonState);
 
     // Keep reading from HC-05 and send to Arduino Serial Monitor
    //if (BTserial.available())
    //{  
        //c = BTserial.read();
        //Serial.write(c);
    //}
 
    // Keep reading from Arduino Serial Monitor and send to HC-05
    //if (Serial.available())
    //{
     //   c =  Serial.read();
 
        // mirror the commands back to the serial monitor
        // makes it easy to follow the commands
        //Serial.write(c);   
        //BTserial.write(c);  
    //}

    if(buttonState == HIGH)
      BTserial.write('1');
     else
      BTserial.write('0'); 

    delay(10)
}

the Slave:

// Basic bluetooth test sketch. HC-05_slave_38400
// 
// 
//  Uses hardware serial to talk to the host computer and software serial for communication with the bluetooth module
//
//  Pins
//  BT VCC to Arduino 5V out. 
//  BT GND to GND
//  BT RX to Arduino pin 13 (through a 1117 3.3v regulator)
//  BT TX to Arduino pin 12 (no need voltage divider)
//
//  When a command is entered in the serial monitor on the computer 
//  the Arduino will relay it to the bluetooth module and display the result.
//
// LED(via 1.5kΩ) - D8
// Button(pull-up to 5v) - D7
 
#include <SoftwareSerial.h>
SoftwareSerial BTserial(12, 13); // RX | TX

const byte ledPin = 8;
const byte buttonPin = 7;

char ledState = '1';
bool buttonState = HIGH;
 
void setup() 
{
    Serial.begin(9600);
    Serial.println("Arduino with HC-06 is ready");
 
    // HC-06 default baud rate is 9600
    // HC-06 has only one role - "salve", HC-05 is capable of altering between "slave" and "master".
    // HC-05 default baud rate is 38400
    BTserial.begin(38400);  
    Serial.println("BTserial started at 38400");

    pinMode(ledPin, OUTPUT);
    pinMode(buttonPin, INPUT);
}
 
void loop()
{
  //ledState = digitalRead(ledPin);
  buttonState = digitalRead(buttonPin);

  if(ledState == '1')
    digitalWrite(ledPin, HIGH);
  else if(ledState == '0')
    digitalWrite(ledPin, LOW);

  Serial.print("ledState = ");
  Serial.println(ledState);
 
  // Keep reading from HC-06 and send to Arduino Serial Monitor
  if (BTserial.available())
    //Serial.write(BTserial.read());
    ledState = BTserial.read();
 
  // Keep reading from Arduino Serial Monitor and send to HC-06
  //if (Serial.available())
  //BTserial.write(Serial.read());

  delay(10);
}

As-tu mis le même mot de passe pour les deux HC-05 ?
Et est tu sûr que la vitesse de traitements des données (ou les bauds) son bien à 38400 sur les deux HC-05 ? Je ne parle pas du programme, mais bien des deux HC-05. Le mieux serait d'adapter le programme.

Ty with the following code:

BTserial.begin(9600); for both UNOs.

The same, still no update in Slave.

Found the reason: I made wrong wiring for RX and TX, in SoftwareSerial, it is (RX, TX), not (TX, RX). Thanks all you, your response to this topic smoothed my eager and made me calm for searching.

The new testing verified: when they were setup as 38400, there would no communication, and 9600 was OK, so you were right.

The new question is: the responses were not symmetry - when I clicked button on master, slave led blink instantly, while when I clicked the button on slave, there was 2 seconds or so delay before blinking, although the code were all same, who know the reason?

This is (Fig-1) the wiring diagram between UNO and HC05.
hc5-1
Figure-1:

For AT commands execution, the default Bd = 38400. For data communication between the BTs, the default Bd = 9600.

No, it isn't. This is a communications exercise, the default rate is 9600, and 38400 isn't the default baud rate for anything. This may be your only problem. Just change the code. Configuring HC-05 to communicate at 38400 with software serial may lead to grief anyway.

You mean I should close the communication on Serial and reset BTserial as 38400?

No, indeed quite the opposite.
The baud rate in your written code must match the rate that HC-05 is configured to. The actual configuration is a separate exercise. Have you done that, or is HC-05 still in its default configuration, i.e. 9600 baud?

IF the latter case, i.e. you have not reconfigured Bluetooth to 38400, just stick with 9600 in your code.

I suspect this is mostly stuff you already know, and I only raised this as your comment line is clearly erroneous.

What your problem really is is far from clear. I can only assume that your HC-05 has been properly configured to connect with HC-06 as a master.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.