Serial chat between two boards
Build it step by step
0 of 8 doneUpload the sketch
Same sketch to both boards.
Cross the wires
Pin 11 of each to pin 10 of the other.
Join the grounds
One wire between the GND pins.
Open both monitors
9600 baud, Newline line ending.
Wait five seconds
Each board prints Received: PING with a count.
Type a line
It appears on the other board's monitor.
Break the link
Pull one wire and see what happens.
Try the divider
1 kilohm and 2.2 kilohm, check with the meter.
How do you build a serial chat between two boards?
Two Arduino Uno boards exchange text lines over a software serial link, and each message carries a checksum so corrupted lines are caught. You need Arduino Uno R3 × 2, Resistor 1 kΩ, Resistor 2.2 kΩ, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 100 minutes.
- Level
- Beginner
- Time
- About 100 min
- Parts
- 5
Parts list
- Development BoardsBuyArduino Uno R3 × 2
- PassivesBuyResistor 1 kΩ × 1
- PassivesBuyResistor 2.2 kΩ × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Uno A pin 11 (TX) | Uno B pin 10 (RX) | A talks to B |
| Uno B pin 11 (TX) | Uno A pin 10 (RX) | B talks to A |
| Uno A GND | Uno B GND | Shared ground reference, required |
| Uno A USB | Computer USB port (first port) | Power and serial monitor for A |
| Uno B USB | Computer USB port (second port) or a USB charger | Power and serial monitor for B |
Code
UART serial sends bytes one after another on a single wire, with a start bit, eight data bits and a stop bit, and both ends must agree on the speed, here 9600 baud. Each board has a transmit pin and a receive pin, and the wires cross: the transmit of one goes to the receive of the other. The grounds must also be joined, because the signals are measured against ground and without a shared ground the bytes become garbage. The Uno uses pins 0 and 1 for its USB connection, so this build runs the link on pins 10 and 11 with SoftwareSerial, leaving the USB serial free for the monitor and for uploading. Both boards are 5 volt boards, so the wires can be connected directly. A 5 volt output into a 3.3 volt board needs a divider, such as 1 kilohm in series and 2.2 kilohm to ground, which gives about 3.4 volts, and that is a good thing to try on the breadboard with a multimeter. Messages are lines of text, ended by a newline, followed by an asterisk and a two-digit hex checksum made by XOR-ing all the characters. The receiver recomputes the checksum and prints a warning when it does not match. Upload the same sketch to both boards, open both serial monitors and type.
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <SoftwareSerial.h>
SoftwareSerial link(10, 11); // RX, TX to the other board
const unsigned long REPORT_EVERY = 5000;
char usbBuf[48], linkBuf[64];
byte usbLen = 0, linkLen = 0;
unsigned long lastReport = 0, counter = 0;
byte xorSum(const char *s) {
byte c = 0;
while (*s) c ^= (byte)*s++;
return c;
}
void sendLine(const char *msg) {
byte c = xorSum(msg);
link.print(msg);
link.print('*');
if (c < 16) link.print('0');
link.println(c, HEX); // for example HELLO*3F
}
void handleLine(char *line) {
char *star = strrchr(line, '*');
if (!star) { Serial.println("No checksum, ignored"); return; }
*star = 0;
byte got = (byte)strtol(star + 1, NULL, 16);
if (got == xorSum(line)) { Serial.print("Received: "); Serial.println(line); }
else { Serial.print("BAD checksum on: "); Serial.println(line); }
}
void setup() {
Serial.begin(9600);
link.begin(9600);
Serial.println("Type a line and press Enter (set the monitor to Newline)");
}
void loop() {
while (link.available()) {
char ch = link.read();
if (ch == '\r') continue;
if (ch == '\n') { linkBuf[linkLen] = 0; if (linkLen) handleLine(linkBuf); linkLen = 0; }
else if (linkLen < sizeof(linkBuf) - 1) linkBuf[linkLen++] = ch;
}
while (Serial.available()) {
char ch = Serial.read();
if (ch == '\r') continue;
if (ch == '\n') { usbBuf[usbLen] = 0; if (usbLen) sendLine(usbBuf); usbLen = 0; }
else if (usbLen < sizeof(usbBuf) - 1) usbBuf[usbLen++] = ch;
}
if (millis() - lastReport >= REPORT_EVERY) {
lastReport = millis();
char msg[24];
snprintf(msg, sizeof(msg), "PING %lu", ++counter);
sendLine(msg);
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Both boards on | A PING message every five seconds from each |
| Type HELLO on board A | Received: HELLO on board B |
| Pull the ground wire | Garbled or bad lines, then recovery once restored |
| Divider 1k and 2.2k on 5 V | About 3.4 V at the middle |
| Checksum | Each message ends with an asterisk and two hex digits on the wire |
If it does not work
Nothing received
Check the cross wiring and the shared ground.
Garbled text
Both boards must use 9600 baud.
Only one direction works
Check the other crossed wire.
Messages join together
Set the serial monitor line ending to Newline.
Upload fails
The link uses pins 10 and 11, not 0 and 1, so check the board and port.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the serial chat between two boards?
Arduino Uno R3 × 2, Resistor 1 kΩ, Resistor 2.2 kΩ, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the serial chat between two boards take to build?
About 100 minutes for a beginner maker, in 8 steps.
How do I know the serial chat between two boards works?
Both boards on: A PING message every five seconds from each. Type HELLO on board A: Received: HELLO on board B. Pull the ground wire: Garbled or bad lines, then recovery once restored.
Nothing received: what should I check?
Check the cross wiring and the shared ground.
Garbled text: what should I check?
Both boards must use 9600 baud.
Only one direction works: what should I check?
Check the other crossed wire.
Messages join together: what should I check?
Set the serial monitor line ending to Newline.
