# SoftwareSerial example does not work

**URL:** <https://forum.arduino.cc/t/softwareserial-example-does-not-work/394444>\
**Category:** Networking, Protocols, and Devices\
**Created:** [June 28, 2016, 9:34am UTC](https://forum.arduino.cc/t/softwareserial-example-does-not-work/394444 "2016-06-28T09:34:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamtawon](https://avatars.discourse-cdn.com/v4/letter/i/b3f665/32.png) [@iamtawon](https://forum.arduino.cc/u/iamtawon)\
**Post date:** [June 28, 2016, 9:34am UTC](https://forum.arduino.cc/t/softwareserial-example-does-not-work/394444/1 "2016-06-28T09:34:41Z")

</div>

Dear All

I'm having a problem with Softwareserial function, I am using code that come with Arduino's IDE 1.6.9  
on Arduino UNO with wire jumper connect pin 0 (UNO's Rx) to pin 11, pin 1 (UNO's Tx) to piin 10. the code are of following

```cpp
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

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

```

when connected I expect the serial monitor to show Goodnight moon! on 57600 baud rate window and  
Hello, world? on 9600 baud rate window after reset

what I had on 57600 is  
Goodnight moon!  
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

and on 9600  
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

I tried swaping pins, changing pin but none seem to work except I use only softwareserial or hardware serial

Any ideas?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 28, 2016, 9:59am UTC](https://forum.arduino.cc/t/softwareserial-example-does-not-work/394444/2 "2016-06-28T09:59:05Z")

</div>

> Any ideas?

Yes. Use SoftwareSerial the way it is intended to be used. That is, it is to be used to read data from an EXTERNAL device that sends serial data. It is NOT intended to be used to read from the hardware serial port.

---

<div class="post-metadata">

**Author:** ![Robin2](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robin2/32/216045_2.png) [@Robin2](https://forum.arduino.cc/u/Robin2)\
**Post date:** [June 28, 2016, 11:26am UTC](https://forum.arduino.cc/t/softwareserial-example-does-not-work/394444/3 "2016-06-28T11:26:36Z")

</div>

It may be possible to use SoftwareSerial to read or write data to the HardwareSerial port (though I can't imagine why you would want to). But it would be ESSENTIAL that they both use the same baud rate.

And start with 9600 baud because SoftwareSerial is a poor perfromer.

...R

---

<div class="post-metadata">

**Author:** ![dev\_1](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dev_1/32/215847_2.png) [@dev\_1](https://forum.arduino.cc/u/dev_1)\
**Post date:** [June 28, 2016, 12:05pm UTC](https://forum.arduino.cc/t/softwareserial-example-does-not-work/394444/4 "2016-06-28T12:05:50Z")

</div>

It is perfectly ok to try a simple echo program, where you wire the HardwareSerial port to a software serial port. However:

- They both have to be at the same baud rate. Sending at 57600 cannot be read by a receiver at 9600.

- The absolute best alternative to HardwareSerial is AltSoftSerial, but it only works on certain pins (8 & 9 on an UNO).

- SoftwareSerial disables interrupts for _very_ long periods of time. This can cause the HardwareSerial port to lose data, but not in your particular example.

- [NeoSWSerial](https://github.com/SlashDevin/NeoSWSerial) is much more efficient than SoftwareSerial. Unless you need a baud rate other than 9600, 19200 or 38400, there is no reason to shoot yourself in the foot with SoftwareSerial.  
Cheers,  
/dev

---

<div class="post-metadata">

**Author:** ![dunnleaddress](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dunnleaddress/32/1189681_2.png) [@dunnleaddress](https://forum.arduino.cc/u/dunnleaddress)\
**Post date:** [December 10, 2017, 7:26am UTC](https://forum.arduino.cc/t/softwareserial-example-does-not-work/394444/5 "2017-12-10T07:26:29Z")

</div>

Hi,

like other has said, for an example declaration below

SoftwareSerial mySerial(10, 11); // RX, TX

you need to have an external device that has output TX, RX respectively connected to (10, 11) or RX, TX for this

sample program to output "Hello, world?" just try you will see. do not worry about the actual signals from external device TX, RX. the example will always give hard coded value "Hello, world?"

Thanks also to @Robin2!

"Two or three hours spent thinking and reading documentation solves most programming problems." helps me.

---

<div class="post-metadata">

**Author:** ![felixanosike](https://avatars.discourse-cdn.com/v4/letter/f/bc79bd/32.png) [@felixanosike](https://forum.arduino.cc/u/felixanosike)\
**Post date:** [March 14, 2019, 12:47pm UTC](https://forum.arduino.cc/t/softwareserial-example-does-not-work/394444/6 "2019-03-14T12:47:45Z")

</div>

Hi all!  
I can get my 3G shield to send text to a number. I discovered that the software serial is not communicating.  
can any one help please!

#include \<SoftwareSerial.h\>

SoftwareSerial mySerial(7,8); //  
#define DEBUG true

void setup()  
{  
mySerial.begin(19200); // the GPRS baud rate  
Serial.begin(19200); // the GPRS baud rate  
sendData("AT+CMGF=1",2000,DEBUG);//Because we want to send the SMS in text mode  
delay(100);  
sendData("AT+CMGS="+2348134627229"",2000,DEBUG);//send sms message, be careful need to add a country code before the cellphone number  
delay(100);  
sendData("Hello,Elecrow!",2000,DEBUG);//the content of the message  
delay(100);  
mySerial.println((char)26);//the ASCII code of the ctrl+z is 26  
delay(100);  
}

void sendData(String command, const int timeout, boolean debug)  
{  
String response = "";  
mySerial.println(command);  
long int time = millis();  
while( (time+timeout) \> millis())  
{  
while(mySerial.available())  
{  
char c = mySerial.read();  
response+=c;  
}  
}  
if(debug)  
{  
Serial.print(response);  
}  
return response;  
}

void loop()  
{  
if(mySerial.available())  
{  
char SerialInByte;  
SerialInByte = (unsigned char)mySerial.read();  
Serial.print( SerialInByte );  
}  
}

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 14, 2019, 12:53pm UTC](https://forum.arduino.cc/t/softwareserial-example-does-not-work/394444/7 "2019-03-14T12:53:22Z")

</div>

```arduino
          char SerialInByte;

```

It is not a good idea to use a type in a name, when the type in the name is not the type of the variable.

Why are you reading serial data in two places?

> I can get my 3G shield to send text to a number.

So, what is the problem?

Which shield are you using? Is it actually connected to pins 7 and 8?

---

<div class="post-metadata">

**Author:** ![arnoldvillasanta](https://avatars.discourse-cdn.com/v4/letter/a/76d3ee/32.png) [@arnoldvillasanta](https://forum.arduino.cc/u/arnoldvillasanta)\
**Post date:** [October 8, 2019, 7:54pm UTC](https://forum.arduino.cc/t/softwareserial-example-does-not-work/394444/8 "2019-10-08T19:54:00Z")

</div>

In case anyone still needs a solution for this:

1. You need to have two arduino boards  
a. Board 1 - just load the code  
b. Board 2 - delete the write command for both serial and myserial before loading  
c. Connect Board 1 and board 2: pins 0 to 1 and 1 to 0 as well as pins 10 to 11 and 11 to 10. Don't forget to connect the GRND of both boards... this will make sure the wave form of tx/rx is pulled down to 0V when sending 0 bit.  
c. Board 2 stays connected to computer with serial monitor turned on.  
d. Board 1 to be powered on by external power/adaptor  
e. Once board 1 is powered up, it will run the write commands to both serial and my serial.  
f. Board 2 will then receive both messages and write them down in the serial monitor.

2. If in case the message is jumbled up:  
a. Change the code in Board 1:  
Insert delay(1000) between serial and myserial write commands.

3. You can also enhance the code in Board 2:  
a. Change if clause to while clause  
b. add delay(5) after the write commands. Board 1 might have some delay transmitting the message which might cut the while loop in board 2 prematurely.

If you want to use SINGLE ARDUINO BOARD ONLY:  
a. in the code change serial baud rate to 9600  
b. apply all the code changes stated above that are applied to board 1.  
c. connect pins 0 to 11 and 1 to 10  
c. run the code

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 11:00am UTC](https://forum.arduino.cc/t/softwareserial-example-does-not-work/394444/9 "2021-05-06T11:00:53Z")

</div>

Closed on May 6, 2021, 11:00am UTC


