Regarding Software Serial

Hi. Actually I want to access my hc-05 module using software serial library on arduino uno. But it doesn’t work. My hc-05 module is okay its perfectly working on the ‘0’ and ‘1’ serial communication pins. For software serial i hv used ‘10’ & ‘11’ as Rx & Tx respectively. I uesd “mySerial.listen()” to enable the Rx pin ‘10’. Its not working.
personally, I think there is no need of “mySerial.listen()” as for this case only one device is connected using software serial. I just need to work on a basic example-turning on a led using bluetooth and software serial.
I would also like to know for two or more devices communicating using single arduino how the software serial will work and what will be the code.
I am attaching my code for your better understanding of this problem.

BT_module3.ino (587 Bytes)

Include short programs in your Post so people don’t have to download files

Code from Original Post

#include <SoftwareSerial.h>

#define rx 10
#define tx 11
#define led 13

//char d;

SoftwareSerial mySerial(rx,tx);
void setup() {
  // put your setup code here, to run once:
      Serial.begin(9600);

    mySerial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
    String c ="";
     mySerial.listen();
     while(mySerial.available()>0){
       char d =(char)mySerial.read();
       c += d;
        Serial.write(d);
       }
//    Serial.println(c);
     if(c == "a")
     digitalWrite(led,HIGH);
     else if( c == "b")
     digitalWrite(led,LOW);
}

…R

Serial.write(d);

what you see in Serial monitor, when Uno executes the above line?

I never had any issue with SoftwareSerial and HC-05/06

I have used SoftwareSerial and I don't recall needing to use .listen(). I wonder {a} what happens if you remove it or {b} what happens if you put it in setup(). My guess is that the way you are using it interferes with receiving the data.

You do need to use .listen() if you are trying to use multiple copies of SoftwareSerial - but really you shouldn't do that. Multiple copies of SoftwareSerial do not work well - much better to use a Mega with 3 extra HardwareSerial ports.

Have a look at the examples in Serial Input Basics

...R

I solved the problem yesterday, after making a fresh start. It's really very simple and easy, approach is more or less same to the actual one(when you use '0' & '1' as your serial pin).
It's the Software Serial library example that directed me the wrong way.

However,thanks to you all for helping me. But i don't know how to put the code in the message without attaching it. Please tell me.

However,thanks to you all for helping me. But i don't know how to put the code in the message without attaching it. Please tell me.

If you open Robin2's or sarouje's reply by using 'Quote', you can see how it's done

type
** **[code]** **

paste your code after that
type
** **[/code]** **
after that

sarouje:
[code]Serial.write(d);[/code]

what you see in Serial monitor, when Uno executes the above line?

I never had any issue with SoftwareSerial and HC-05/06

It's the Software Serial library example that directed me the wrong way.

Can you please expand on this statement ? What was wrong and how did you correct it ?

Thanks for help. In the software serial example there is two modules that are serially connected to arduino. And in that program one module received data is transferred to the other module and vice versa. I dont understand that problem.

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

I dont understand that problem

What is the problem? Or don't you understand the program?