To have two serial ports on Arduino board like Uno use SoftwareSerial.h
.
Example
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.println("Hello!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
Now after opening Serial monitor
you should see Hello! and then you can test SoftwareSerial
.
DO NOT FORGET!!!
When you connect to pins 2,3 or etc, this is TTL voltage level. You can't connect direct to RS232.