pcbway




arduino software serial, software serial arduino, software serial, software serial in arduino, virtual port arduinoHello friends, I hope you all are fine and having fun. In today’s tutorial, I am going to show you How to use Arduino Software Serial. In my previous tutorial, we have had a look at How to use Arduino Serial Write and How to use Arduino Serial Read. In both of these tutorials, we have done the hardware Serial Communication. But we all know that Arduino has just one Serial Port placed at pins 0 and 1. So, if you are having two or more serial modules, then there’s a difficulty in adding two modules because we just have one serial port. So, in such cases there’s a need to add one more serial port and that serial port can be created at any two pins of Arduino and that serial port is called software serial.

Software Serial is also named as Virtual Serial Port. It’s really very comfy if you are working on serial modules. IF you ask me I have never used hardware serial port because pin # 0 and pin # 1 are also used for uploading code and debugging the code via Arduino Serial Monitor. So, I always connect my Serial modules via software serial and then check their output on Serial Monitor. So, let’s get started with How to use Arduino Software Serial:

How to use Arduino Software Serial ?

  • I am gonna use Proteus software for testing the codes. So you can download the Proteus Simulation by clicking the below button:

Download Simulation & Code

  • First of all, let me tell you where you can find Examples of Software Serial.
  • Arduino has a Library of Software Serial in it. If you can’t find its library then you should download the Software Serial Library.
  • Now copy and paste the below code in your Arduino:

  • In the above code, we have first included the Arduino Software Serial Library using #include<SoftwareSerial.h>.
  • After that, I have created the SoftSerial object and its parameters are SoftSerial(RX, TX), so in the above code pin # 2 has become RX of our Arduino Software Serial and pin # 3 become TX.
  • Now our SoftSerial object is ready so next thing we have done is SoftSerial.begin(9600), here we have started our software serial and the baud rate set is 9600.
  • Now design a small circuit in Proteus, you will need Arduino Library for Proteus to use Arduino in Proteus, as shown in below figure:

arduino software serial, software serial arduino, software serial, software serial in arduino, virtual port arduino

  • Now get our Arduino Hex File and upload it in your Proteus.
  • Now run your Proteus Simulation and you will get something as shown in below figure:

arduino software serial, software serial arduino, software serial, software serial in arduino, virtual port arduino

  • So, its printed there that one is hardware serial and second is software serial and you can see the software serial is connected to Pin # 2 and Pin # 3.
  • Now when you write something in the Hardware Serial, it will also get printed in the Software Serial, that’s the code which we have added in the loop() section.
  • The below videos will give you better idea of how it’s working.

So, that’s all for today, I hope you have enjoyed this Arduino Software Serial example. Download the Simulation from above button and try to design it on your own. Take care and have fun !!! 🙂

3 Comments

  1. @Syed, thanks for the article. I would also like to know, how to send serial data from a master device to multiple slaves. Each slave need to get different data and need to have its unique addresses as well. An article on these line would be very helpful.
    Thanks again,
    Madhav

  2. If I change the code to write on SoftwareSerial and read with HardwareSerial the simulation doesn’t work. This is the change:
    void loop()
    {

    if (SoftSerial.available())
    {
    char data = SoftSerial.read();
    Serial.print(data);
    }
    }

    The SoftSerial.available() always retuns false. Althought I wrote on the virtual terminal. Do you know the reason?
    A lot of thnaks

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment