I have configured both the HC-05 as a master-slave pair and they are able to pair as well. However, when I try to send out any data through a simple code and receive it, the received data is always a number. First I thought it was a random number then I realized the outputs repeat for a specific input.
Eg: I send out 123 then, I receive 255
I send out "hi" I receive 247
I send out "hello" I receive 206 and 255
Note that these outputs are always the same for the mentioned inputs, and I have tested both with numbers and string
For testing, I connected the module to my mobile phone and received it through a serial Bluetooth app on phone. The data was received perfectly as was sent. The above garbling of values was not happening.
Note that I have also tried avoiding the usage of <SoftwareSerial.h> library and directly connecting to rx and tx of the arduino uno and nano, with and without a voltage divider at the receiver, so that is not the issue.
I am using the above codes for receiver and sender respectively
Can you please help me debug this problem?
Note: I am using this Bluetooth connection to send accelerometer data from an MPU6050 module connected to Arduino nano (Sender) to a robotic arm servo motors connected to Arduino uno (receiver).
As you have said Serial.println(bt.read()); numerical value but it's gives me numbers like 255 and 247 when I send out 123.
Thank you for the reply.
This is the code I used to send hello
I used the same receive code.
Also, note that the end result I want is to send out numerical angle values from the accelerometer to the servo motors. The string was just to troubleshoot.
Please post a wiring diagram (hand drawn is preferred, with pins and connections clearly labeled) and state which Arduino you are using.
If you are using a 5V Arduino, do you have the required logic level converter between Arduino TX and the 3.3V Bluetooth RX? If not, you will damage both boards.
You can create test skecthes to see that whenever LEDbut switch (Fig-1) is pressed at the sender/Master side, the blueLed at the receiver/Slave side turns on.
The diagram is difficult to interpret and lacks pin designations on the radios, but it might be OK.
When sending the string "hello", five characters should have been sent, and five numbers representing those characters should have been printed, specifically 104 (for ASCII h), 101 (for ASCII e), etc. but I don't see any obvious explanation for your observations.
Maybe the two BT modules are not actually talking to each other, and you are receiving random noise. Take a look at the tutorials on Martyn Currey's site, linked above.
I found out that 1 of the modules is version 2.0 and the other is version 4.0 using the AT+VERSION command in command mode.
Is that why the data is getting garbled, but also has a pattern?
Another observation I have made is that, whenever I make the new one as the master and give the old one's address to bind, the pairing is not happening. But, when I give the new one's address to the old one to bind and make the old one the master, the pairing is happening.
Does anyone have a suggestion apart from replacing the module?
That still doesn't explain why the data is getting corrupted when setting up v4 as the slave and v2 as the master and they both have successfully paired.
I tried both modules individually with my phone, keeping their configurations unchanged, that is, v2 is still the master and v4 is still the slave and master is bound to the address of the slave.
The v4 module is working perfectly in both receiving data sent out through phone (only numerical values according to code) and sending data (123 is sent out though v4 module) and receiving through the phone.
However, the v2 module is not, it's is receiving 0 always, and when it sends out data, the phone receives corrupted data
Sender code:
Hello everyone, turns out the issue was the version difference or with the module, because now I tried the same master-slave configuration with 2 version 4 HC-05 modules and they worked perfectly.