Examples > Software Serial Library
Arduinos have built in support for serial communication on pins 0 and 1, but what if you need more serial ports? The SoftwareSerial Library has been developed to allow serial communication to take place on the other digital pins of your Arduino, using software to replicate the functionality of the hardwired RX and TX lines. This can be extremely helpful when the need arises to communicate with two serial enabled devices, or to talk with just one device while leaving the main serial port open for debugging purpose.
In the example below, digital pins 2 and 3 on your Arduino are used as virtual RX and TX serial lines. Digital pins 4 and 5 are another virtual serial port. Only one software serial port can listen at a time. When starting multiple Software Serial ports, the most recent one called with serial.begin() is listening. To listen on another, you must call serial.listen() for the port you wish to receive data on.
Here, ss2 on lines 4 and 5 starts last. By default it is listening when the program starts. You want to listen on pins 2 and 3, named "ss", so you call ss.listen(). Once you receive a "?" on the serial port ss, you begin listening on ss2 and enter the loop().
There is no circuit for this example. Make sure that your Arduino is attached to your computer via USB to enable serial communication.