As discussed in #3 , Arduino Uno has only one in built Serial port. But when we have more than one device to communicate with the Arduino board, can we proceed with Uno ? If yes, how can we proceed further as Uno has only one serial port? The answer is we can create additional Serial ports by simple programming. This is shown below:
#include<SoftwareSerial.h>
SoftwareSerial Serial2(3,4); //here 3 is RX & 4 is TX and Serial2 is the name of the
//created port & by default name of inbuilt Serial port(0,1)
// is Serial.
Once we include the above two lines of code, we can use 3,4 pins as RX & TX with the name Serial2 respectively.
to begin we use the command Serial2.begin(9600);
to read Serial2.read();
to write Serial2.write();
** Note that if you want to communicate with the computer you should use Serial port only not any other created ports.
#include<SoftwareSerial.h>
SoftwareSerial Serial2(3,4); //here 3 is RX & 4 is TX and Serial2 is the name of the
//created port & by default name of inbuilt Serial port(0,1)
// is Serial.
Once we include the above two lines of code, we can use 3,4 pins as RX & TX with the name Serial2 respectively.
to begin we use the command Serial2.begin(9600);
to read Serial2.read();
to write Serial2.write();
** Note that if you want to communicate with the computer you should use Serial port only not any other created ports.