HC-05 can´t receive data

Hi,

i googled arround a few hours but i can´t find a solution for my problem:
I can connect my Arduino Mega to my HC-05 but I can´t send any data from my PC or my Android via Bluetooth. Reverse it works. I can receive messages from my Arduino via Bluetooth.
It seems to be a one-way connection. Any messages that are send from me are ignored.
This is my module:
http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItemVersion&item=360663422584&view=all&tid=403590625023
Can anyone help me?
Thanks,
daubli

I solved the problem. You have to use SoftwareSerial to connect properly to this device:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX
int LED = 13;
char character;

void setup()  
{
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  pinMode(LED, OUTPUT);
}

void loop() // run over and over
{
    String Data = "";
    while(mySerial.available()) {
     character = mySerial.read();
     Data.concat(character);
     delay (10);
    }
    
    if (Data == "1") digitalWrite(LED, HIGH);
    if (Data == "0") digitalWrite(LED, LOW);
}

This page helped me: Arduino - Home

I solved the problem. You have to use SoftwareSerial to connect properly to this device:

I am using several HC-05 BT modules with hw serial, no problem (with 328p, 1284p and 5 other mcus).

daubli:
You have to use SoftwareSerial to connect properly to this device:

No you don't. I don't know what your problem was but it was probably trivial, and you solved it by accident. I thought it was most likely at the PC end.

Had the same problem myself. Struggled for days with comms working one way only. Turns out not all the pins on the mega board can rx data. I used pins 50 and 51 and everything fell into place. Here is amended code.

_2301txrxsol4mega.ino (1.02 KB)

Arcticfox:
Had the same problem myself. Struggled for days with comms working one way only. Turns out not all the pins on the mega board can rx data.

That is indeed correct, and the most appropriate pins are those that are clearly marked for that purpose, being pins 0, 15, 17, 19

I used pins 50 and 51 and everything fell into place. Here is amended code.

The pins you use are the SPI bus pins and you are using software serial. I won't ask what possessed you to do that on a Mega when four hardware serial channels are available to you. It might be something you regret later, but at least it works for the moment. Having said that, if you must use software serial, I understand the software serial library allows connection to digital pins other than the SPI bus, but I'm not sure what. I guess using it with the hardware serial pins would be a bad idea.

I couldn't get it to work on Mega Rx channel 0. Trawled forums and didn't find any info apart from the fact that not all channels on Mega can receive data. I also found alot of people in the same situation as me. Tried Rx1 on channel 19 nothing here either although I haven't spent alot of time on this and could be wrong. Nevertheless still works as robot controller now that data is flowing in both directions.

Arcticfox:
I couldn't get it to work on Mega Rx channel 0.

Possibly because you were using Software serial on the hardware serial pins

Trawled forums and didn't find any info apart from the fact that not all channels on Mega can receive data. I also found alot of people in the same situation as me.

This may be due to people using different software serial libraries. and not helped by
http://arduino.cc/en/Main/arduinoBoardMega2560
http://arduino.cc/en/Reference/SoftwareSerial
apparently conflicting, so I think you might need to be careful if you want to use other pins.

Nevertheless still works as robot controller now that data is flowing in both directions.

OK. If it works, stick with it. In the unlikely event that you have a problem later, fix it then.

hello people,
we are working with 2 Arduino boards each connected with Wireless Bluetooth Transceiver HC-05 RS232 / TTL Base Board. We generate 6 digit codes on one board and want to receive them on other. The codes transmitted by one HC05 are detected via android application "SENA BTERM", but the other HC-05 is receiving nothing
the code for the transmitting end is:

#include <SoftwareSerial.h>
#define RxD 10
#define TxD 11
#define Reset 5
#define PIO11 8
#define Led 13
#define RTS 4
SoftwareSerial blueToothSerial(RxD,TxD);

void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(Led, OUTPUT);
pinMode(PIO11, OUTPUT);
digitalWrite(PIO11, HIGH);
pinMode(Reset, OUTPUT);
digitalWrite(Reset, LOW);
pinMode(RTS, INPUT);
setupBlueToothConnection();
}

void setupBlueToothConnection()
{
enterATMode();
sendATCommand();
sentATCommand("UART=9600,0,0");
sentATCommand("ROLE=1");
enterComMode();
}
void enterATMode()
{
blueToothSerial.flush();
delay(500);
digitalWrite(PIO11, HIGH);
resetBT();
delay(500);
blueToothSerial.begin(9600);

}
void resetBT()
{
digitalWrite(Reset, LOW);
delay(2000);
digitalWrite(Reset, HIGH);
}
void sendATCommand()
{
blueToothSerial.print("AT\r\n");
delay(100);
}

void sentATCommand(char *command)
{
blueToothSerial.print("AT");
if(strlen(command) > 1){
blueToothSerial.print("+");
blueToothSerial.print(command);
delay(100);
}
blueToothSerial.print("\r\n");
}

void enterComMode()
{
blueToothSerial.flush();
delay(500);
digitalWrite(PIO11, LOW);
resetBT();
delay(500);
blueToothSerial.begin(9600);
}

void loop()
{
Serial.println(blueToothSerial.print("12345"));
delay(1000);
}

and the code for the receiving end is:

#include <SoftwareSerial.h>
#define RxD 50
#define TxD 51
#define Reset 5
#define PIO11 8
#define Led 13
#define RTS 4
SoftwareSerial blueToothSerial(RxD,TxD);

void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(Led, OUTPUT);
pinMode(PIO11, OUTPUT);
digitalWrite(PIO11, HIGH);
pinMode(Reset, OUTPUT);
digitalWrite(Reset, LOW);
pinMode(RTS, INPUT);
setupBlueToothConnection();
}

void setupBlueToothConnection()
{
enterATMode();
sendATCommand();
sentATCommand("UART=9600,0,0");
sentATCommand("ROLE=0");
enterComMode();
}
void enterATMode()
{
blueToothSerial.flush();
delay(500);
digitalWrite(PIO11, HIGH);
resetBT();
delay(500);
blueToothSerial.begin(9600);

}
void resetBT()
{
digitalWrite(Reset, LOW);
delay(2000);
digitalWrite(Reset, HIGH);
}
void sendATCommand()
{
blueToothSerial.print("AT\r\n");
delay(100);
}

void sentATCommand(char *command)
{
blueToothSerial.print("AT");
if(strlen(command) > 1){
blueToothSerial.print("+");
blueToothSerial.print(command);
delay(100);
}
blueToothSerial.print("\r\n");
}

void enterComMode()
{
blueToothSerial.flush();
delay(500);
digitalWrite(PIO11, LOW);
resetBT();
delay(500);
blueToothSerial.begin(9600);
}

void loop()
{
Serial.println(blueToothSerial.read());
delay(1000);
}

the problem is that app shows that data is correctly transmitted, but the receiving side shows 0 0 0 0 0 0 on the serial monitor window. As the HC05 is by default configured as a slave, so we checked the receiving end without programming the Bluetooth as well. works neither way.
Can anybody please help us in communication between these two boards. where are we going wrong?

void enterATMode()
{
blueToothSerial.flush();
delay(500);
digitalWrite(PIO11, HIGH);
resetBT();
delay(500);
blueToothSerial.begin(9600);

Afaik HC-05 needs 38400baud to work in the AT mode..

its still not working.. any other ideas, i think the slave HC-05 is not receiving anything :frowning: while the transmission is going well as intercepted by the android app.

Wrong radio system? This may be a matter of language, but your post implies that you have one HC-05 connected to Android OK, but cannot talk to the other HC-05 at the same time. Not much surprise there. If you want to connect to another HC-05 you need to pre-programme them for this sort of operation and they can then connect automatically, but don't expect to talk to Android in the meantime.

The person with the best work, and ability to talk about it, is AgentNoise in a thread just a couple of weeks or so ago. You might try trawling for that.