HC-05 reading wrong data

Hi, I wanna get some help on my HC-05 which is reading wrong data from a source. This module is working fine recently and communicating good with android phone and my ESP32. But earlier, when I tried to play again with my bluetooth car it didn't work. So I troubleshoot the project and found out that my HC-05 is reading the data in an odd way rather than it was supposed to.
For example, when I send a character "1" to my HC-05 it will read this as 49 13 10.

For troubleshooting I used Serial Bluetooth Terminal app.
And this is the code I used

#include <SoftwareSerial.h>

SoftwareSerial bt(0,1);
void setup() {

Serial.begin(9600);
bt.begin(9600);
}

void loop()

{
if(bt.available())
Serial.println(bt.read());
}

This is my serial monitor and the app.


49 is the ASCII code for '1'
13 is ASCII carriage return
10 is ASCII line feed

rather than printing the character you are printing the integer ASCII value
try casting the received byte to a char, e.g.

if(bt.available())
    Serial.println((char)bt.read());
1 Like

No matter what else you are messing about with, using software serial on the hardware serial pins is a recipe for certain disaster, so you need to fix that first by putting software serial somewhere else.

2 Likes

1<CR><LF>
2<CR><LF>
3<CR><LF>
4<CR><LF>

1 Like

just noticed you are using an ESP32 - which version? many have builtin Bluetooth Classic and BLE
also as @Nick_Pyner mentions why use SoftwareSerial on a device with Hardware serial ports

my bad. .I switched the pins to 9 &10 but still the same problem

ESP32DevBoard

yes, i used it as master to hc05 slave

my bad, i changed it to pin 9&10 but still the problem exist

Can you please provide a hand drawn sketch of the arrangement. What is connected to what, and what are the sending codes?

Some device is sending a which, apparently, you don't want and wish to eliminate.

here is a ESP32 example using pins 15 and 16 as Serial1 hardware port

// ESP32  Serial1 test - for loopback test connect pins 16 and 15

#define RXD1 16
#define TXD1 15

void setup() {
  // initialize both serial ports:
  Serial.begin(115200);
  Serial1.begin(115200, SERIAL_8N1, RXD1, TXD1);
  Serial.println();
  Serial.println("\n\nESP32 serial1  test Rx pin 16 Tx pin 15");
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }

  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    //Serial.write(inByte);
    Serial1.write(inByte);
  }
}

As I have understood -- your hardware setup is:

ESP32 Board --> Built-in Classic BT of ESP32 as Master --> External HC05 BT as Slave --> Android Phone's BT is Master.

Is that correct?

1 Like

i have two different setups.
ESP32(master)-->HC05(slave)
AndroidPhone(master)-->HC05(slave)

it is now working thanks to @horace . just need to convert the data to char.

Thanks! this works!

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