Help needed in Bluetooth communication using HC-05 to HC-05 for Mega2560

I wanted to establish bluetooth link between Two ardruino Mega2560 using HC-05. I already binded the devices using AT commands, by help of “HC-05 Bluetooth link with zero code” by Phillipe Cantin

But after binding i am unable to do next i.e. communication i wrote sample code but its not even sending anything…no Tx Rx led blinking exept Void Setup(); it not even printing serial commands in if(BTSerial.available()){} plz check code bellow and advise …thanks

\Transmitter

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX
int red=11;
void setup()
{ pinMode(13, OUTPUT);
Serial.begin(9600);
Serial.println(“Red”);
Serial.println(red);
BTSerial.begin(9600); // HC-05 speed it checked and OK by “AT+UART?”
}

void loop()
{
delay(100);

if (BTSerial.available()){

BTSerial.write(red);
Serial.println(“Red Sending”);\\NOT GOING HERE…NO SERIAL PRINTING
}
delay(100);
}

\\Reciever

#include <SoftwareSerial.h>

SoftwareSerial BTyellow(10, 11); // RX | TX
int yellow=110;

void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
Serial.println(“yellow”);
Serial.println(yellow);
BTyellow.begin(9600);

void loop()
{

delay(100);
if(BTyellow.available()){

Serial.println(“Recieving”); \\NOT GOING HERE…NO SERIAL PRINTING
int incoming = BTyellow.read();

if (incoming > 0)
{
yellow = Serial.parseInt(); //Reads integers as integer rather than ASCI
Serial.println(yellow);
}
}

delay(100);

}

///Plaese Help :slight_smile:

Assuming you have followed the pairing guide to the letter and got all the correct OK replies etc and when the two devices are powered up they pair okay then I think the transmitter code may be a problem.

 if (BTSerial.available()){
       
    BTSerial.write(red);
    Serial.println("Red Sending");\\\\NOT GOING HERE...NO SERIAL PRINTING
  }

will only send when it receives data from the other BT module.

As I understand it you have set up your modules so they auto-connect, but that is as far as you have gone. If the LEDs are not blinking, there should be a connection.

I have not tried this, and the following code is untested, but what I have had round waiting, so you might try it. Note it does not use software serial. Bluetooth goes on Serial1, pins 18,19. I bet you don't have a good reason for using software serial, and will eventually have four very good reasons not to. It assumes serial monitors at both ends but the one on the transmitter is not really necessary.

Good luck.

\Transmitter

void setup() { Serial.begin(9600); Serial.println("start"); Serial1.begin(9600); }

void loop() { Serial.println("Sending"); Serial1.println("hello");; delay(1000); }

\\Receiver

void setup() { Serial.begin(9600); Serial.println("start"); Serial1.begin(9600); }

void loop() { // check if data has been sent if (Serial1.available()) { /* read the most recent byte */ byteRead = Serial1.read();

Serial.write(byteRead);

if(byteRead==10) // chk for CR { Serial.println(); Serial.println("Did I hear that?"); } } }

:-) :-) :-) :-) :-)

yup Nick its working...you are god-damn Tony Stark :-)

Thanks to you also Riva :-)

LoL, I guess that's good to hear. I must find the time to use it myself.........