What is Arduino Software Serial
I feel obligated to post this tutorial after seeing beginners assigning two serial devices to Arduino Uno hardware serial pin which is digital pin 0 (Rx) and digital pin 1 (Tx). Connecting two serial devices results to undefined behavior due to conflicting signals. Arduino Uno, Arduino Nano, and Arduino Mini has only 1 serial port. If you need to connect more serial devices, you have the option to use their big brother; the Arduino Mega which has four serial ports and more pins available. But using the Arduino Mega results to additional cost. The other option is to use the Arduino Software Serial library.
#include "SoftwareSerial.h"
SoftwareSerial swSerial(2,3);
void setup(){
//Initialize HARDWARE serial port
Serial.begin(9600);
//Initialize SOFTWARE serial port
swSerial.begin(9600);
Serial.print("Setup DONE.");
}
void loop(){
// If there is data from software serial
if (swSerial.available()){
Serial.write(swSerial.read()); // Write it to hardware serial
}
// If there is data from hardware serial
if (Serial.available()){
swSerial.write(Serial.read()); // Write it to software serial
}
}