Problem with module bluetooth HC-05

Hi there. I have a problem with my bluetooth module HC-05.
I could configure it and paired it to my cellphone (android) correctly using the SoftwareSerial.h library.
I'm able to change the name, password, and other parameters with the example code, and it works correctly:

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(10, 11); // RX, TX

void setup() {
  Serial.begin(9600);
  bluetooth.begin(38400);
  while (!Serial) {
  }
  Serial.println("Configuración");
}

void loop() { // run over and over
  if (bluetooth.available()) {
    Serial.write(bluetooth.read());
  }
  if (Serial.available()) {
    bluetooth.write(Serial.read());
  }
}

And as this works correctly, I don't believe there's a problem with the circuit (just the bluetooth module connected my arduino UNO vcc-5v, GND-GND, TXD-10, RXD-11).

Just for testing, I want to print to the serial monitor any value recieved via bluetooth, and turning on a led if it is '1'. I'm using the Serial Bluetooth Terminal app, that was recomended to me by a friend.
Here's the code I'm using:

#include<SoftwareSerial.h>
SoftwareSerial BT(10, 11); //RX TX

int ledPin = 13;
char state = '0';

void setup() {
  BT.begin(9600);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  Serial.begin(9600);
}

void loop() {
  if(BT.available()){
    Serial.print("Data recieved: ");
    state = BT.read();
    Serial.println(state);
    if (state == "0"){
      digitalWrite(ledPin, LOW);
    } else {
      if(state == "1"){
        digitalWrite(ledPin, HIGH);
      }
    }
  }
  delay(10);
}


So, I can connect from the app to the bluetooth module (It says Connected in the app), but when I send any message, it doesn't do anything. Neither the led turns on if I send a '1', nor it shows anything in the Serial Monitor.

I have already tried with 3 different HC-05, each of them bought in a different place, and with 3 different Arduinos. I have changed the bauds, the name, and other configurations, I have tried with 4 different programs, I've simplified the code to only show a message with the if(BT.available());, I've changed the pins, the voltage, and nothing.

I've never had this much problem with any other arduino module, I've read forums and watched videos for days, but no matter what I try, it doesn't work.

Do you have any idea what the problem might be? I would appreciate a lot your help

I hope I was clear with my problem, and if you have any further question, don't doubdt to ask it.

Are you using the required voltage divider or logic level shifter from Arduino 5V TX to the HC-05 3.3V RX?

1 Like

What is the baud rate of your HC05 module? In the first sketch you have the Bluetooth serial port set to 38400, in the second to 9600. Did you configure the HC05 to run at 9600 in between writing those two sketches? If the HC05 output is still running at 38400 then the SoftwareSerial port should also run at 38400 baud to match. It is also a good idea for the primary Serial port to match this as well.

BT.begin(38400);
Serial.begin(38400);

You set the variable state as a data type CHAR, so in the IF statement you should use a single quote instead of a double quote.

Not sure this will fix your bigger problem, but I hope it helps!

There is a good tutorial Here you could look at which might help .
If you didn’t put the voltage divider in the Rx line , then you may have killed the hC05 .

Allright, I'll try with the voltage divider (I don't believe the HC-05 is damaged because the configuration is still saying it's OK), and to change for single quote.
As for the bauds, I tried both of them, once at 38400, and another at 9600, but I copied different versions accidentally, (that's why one of them says 9600 and the other 38400).

I've seen plenty of people have problems with bluetooth data because they were confusing or mis-matching data types. For example, if your phone app sends a char '0' and your arduino reads it as an INT, it would see the number 48. On the other hand, if your app sends an INT 0 and your arduino reads it as a CHAR, I believe it would be an undefined CHAR since the first CHAR on the character map is '!' and it has an integer value of 33.

You have to match data types between the app that is sending and the arduino that is receiving.

void loop() 
{
  if(BT.available()){
    //Serial.print("Data recieved: ");
    state = BT.read();
    Serial.println(state);

    if (state == '0')
    {
      digitalWrite(ledPin, LOW);
    } 

    if(state == '1')
    {
      digitalWrite(ledPin, HIGH);
    }
  }

It is possible that just the RX pin burns out, while other parts of the device continue to work.

Always use a level shifter when connecting 5V output pins to 3.3V input pins.

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