If you are trying to communicate between two UNOs using hardware UART Ports, you will face problems as the UART Ports are engaged with the Serial Monitors of the their respective IDEs.
You may create software UART Ports and then connect two UNOs as per following diagram. Write codes to test the functionality of the communication link.
Codes for UNO-1 (sends hello! to UNO-2 and receives OK! from UNO-2)
#include <SoftwareSerial.h>
SoftwareSerial UNO1Serial(6, 7); // RX | TX
// connect UNO1's DPin-6 with UNO2's DPin-7
// Connect UNO1's DPin-7 with UNO2's DPIN-6
void setup()
{
Serial.begin(9600);
UNO1Serial.begin(9600);
}
void loop()
{
while(Serial.available())
{
byte x = Serial.read();
UNO1Serial.write(x);
}
while(UNO1Serial.available())
{
byte x = UNO1Serial.read();
Serial.write(x);
}
}
Codes for UNO-2 (receives hello! from UNO-1 and sends OK! to UNO-1)
#include <SoftwareSerial.h>
SoftwareSerial UNO2Serial(6, 7); // RX | TX
// connect UNO2's DPin-6 with UNO1's DPin-7
// Connect UNO2's DPin-7 with UNO1's DPIN-6
void setup()
{
Serial.begin(9600);
UNO2Serial.begin(9600);
}
void loop()
{
while(Serial.available())
{
byte x = Serial.read();
UNO2Serial.write(x);
}
while(UNO2Serial.available())
{
byte x = UNO1Serial.read();
Serial.write(x);
}
}
Procedures:
1. Upload codes into flash of UNO-1. Bring in the Serial Monitor (SM1) of UNO-1.
2. Upload codes into flash of UNO-2. Bring in the Serial Monitor (SM2) of UNO-2.
3. In the InputBox of SM1, type hello! and click on the send button. Check that the message has appeared on the SM2.
4. In the InputBox of SM2, type OK! and click on the send button. Check that the message has appeared on the SM1.