To avoid interference from your computer under simpleAnother way to do serial communication, you can between Arduinos is to use the SoftwareSerial option,library using (digital) pins of your choosing for serial communication between the Arduinos. Incidentally, it avoids interference from your computer under simple serial communication,
The SoftwareSerial library allows serial communication on other digital pins of an Arduino board, using software to replicate the functionality (hence the name "SoftwareSerial"). It is possible to have multiple software serial ports with speeds up to 115200 bps. A parameter enables inverted signaling for devices which require that protocol.
https://docs.arduino.cc/learn/built-in-libraries/software-serial
It takes just a little preparation and understanding, but not much.
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
// Set up a new SoftwareSerial object
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
void setup() {
// Define pin modes for TX and RX
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// Set the baud rate for the SoftwareSerial object
mySerial.begin(9600);
}
void loop() {
if (mySerial.available() > 0) {
mySerial.read();
}
}
In this example (copied from the above/linked article), you would use the mySerial variable to do your Arduino to Arduino communication in the same way as you use the standard serial connection. You would also need to wire the RX and TX pins of one Arduino to the TX and RX pin of the other Arduino, respectively.
One of the benefits of learning how to use the SoftwareSerial library is that there are many communication devices that use serial connection, such as Bluetooth modules (HC-05, HC-06, and HM-10 for example), that you can now use with ease. In this case, you can replace the wires I had you add with a Bluetooth module and communication between the 2 Arduinos wirelessly. Or you can instead communicate with a mobile device with the Bluetooth module.
https://www.instructables.com/Tutorial-Using-HC06-Bluetooth-to-Serial-Wireless-U-1/
Or you could access the internet with a WiFi module over SoftwareSerial.
https://www.taintedbits.com/2017/07/21/arduino-uno-esp8266-software-serial/