How to communicate between Arduinos using SoftwareSerial.h

Sir,
I tried working with your code but it did not work out.
I have only changed the pins from 4 and 5 to 6 and 7.
There is no output on serial monitor on the receiver side. Sir, what may be the bugs.
Thank you.

@ShaileshKumar, you have re-awakened a Thread that was 5 years dead.

I am suggesting to the Moderator to move your question to its own Thread.

The please tell us in detail what you are trying to do, post the program(s) you are using and tell us exactly what happens when you run the programs and what you want to happen that is different.

...R

If you are trying to communicate between two UNOs using hardware UART Ports, you will face problems as the UART Ports are engaged with the Serial Monitors of the their respective IDEs.

You may create software UART Ports and then connect two UNOs as per following diagram. Write codes to test the functionality of the communication link.

Codes for UNO-1 (sends hello! to UNO-2 and receives OK! from UNO-2)

#include <SoftwareSerial.h>
SoftwareSerial UNO1Serial(6, 7); // RX | TX
// connect UNO1's DPin-6 with UNO2's DPin-7 
// Connect UNO1's DPin-7 with UNO2's DPIN-6
  
void setup() 
{
    Serial.begin(9600);
    UNO1Serial.begin(9600);
    
}
 
void loop()
{
    while(Serial.available())
    {
      byte x = Serial.read();
      UNO1Serial.write(x);
    }

    while(UNO1Serial.available())
    {
      byte x = UNO1Serial.read();
      Serial.write(x);
    }
}

Codes for UNO-2 (receives hello! from UNO-1 and sends OK! to UNO-1)

#include <SoftwareSerial.h>
SoftwareSerial UNO2Serial(6, 7); // RX | TX
// connect UNO2's DPin-6 with UNO1's DPin-7 
// Connect UNO2's DPin-7 with UNO1's DPIN-6
  
void setup() 
{
    Serial.begin(9600);
    UNO2Serial.begin(9600);
    
}
 
void loop()
{
    while(Serial.available())
    {
      byte x = Serial.read();
      UNO2Serial.write(x);
    }

    while(UNO2Serial.available())
    {
      byte x = UNO1Serial.read();
      Serial.write(x);
    }
}

Procedures:
1. Upload codes into flash of UNO-1. Bring in the Serial Monitor (SM1) of UNO-1.

2. Upload codes into flash of UNO-2. Bring in the Serial Monitor (SM2) of UNO-2.

3. In the InputBox of SM1, type hello! and click on the send button. Check that the message has appeared on the SM2.

4. In the InputBox of SM2, type OK! and click on the send button. Check that the message has appeared on the SM1.

AltSoftSerial is the best software serial library. Only one instance is allowed, and it is must be used on one of the Input Capture pins (pins 8 & 9 for a UNO, Mini or Nano, see docs here).

My NeoSWSerial is next best. It works on any two pins, but only at baud rates 9600, 19200 and 38400.

SoftwareSerial is the worst choice. It works on any two pins, but it is very inefficient. It disables interrupts for the entire time that a character is being sent OR received, and it cannot do both at the same time (unlike all the other serial choices). This can interfere with other parts of your sketch, other device communications, or with libraries.

I have downloaded, included and tested the NeoSWSerial.h Library; it is working fine with HC05. Thanks.

GolamMostafa:
I have downloaded, included and tested the NeoSWSerial.h Library; it is working fine with HC05. Thanks.

How does that help the OP?

There was never any doubt that it would work.

...R