Summary of Enhancing Projects with Serial Connectivity Between Arduino Boards
Summary: This tutorial explains how to establish serial communication between two Arduino boards (Uno/ Mega) to exchange data and control peripherals. It covers wiring (Tx-Rx cross and common ground), basic Sender/Receiver code using Serial.write and Serial.readBytes, examples controlling an LED via Mega-to-Uno commands, and using pushbuttons on a transmitter to toggle LEDs on a receiver. Proteus simulation and tips for powering one board from another are also included.
Parts used in the Serial Communication between Two Arduino Boards:
- Arduino Uno
- Arduino Mega
- Male-to-male jumper wires (3)
- Push buttons (2)
- LEDs (as required, e.g., onboard LED on pin 13)
- Variable resistor (optional, for transmitting analog values)
- 5V power connection or USB cables/power adapters
- Proteus simulation files (optional)
Two Arduino boards talk to each other over their serial (UART) pins: wire TX of each board to RX of the other, join the grounds, use the same baud rate in both sketches, and wrap every message in start and end markers such as <ON,3> so the receiver always knows where a message begins. This page gives a complete sender and receiver sketch, shows the receiver driving a 16×2 LCD, adds a Mega version and a push-button version, and compares UART with I2C and SPI so you can pick the right link.
Datasheet verified by us. The UART pin names, the frame format and the baud rate error figures at 16 MHz were checked against the ATmega328P datasheet (DS40002061B). Page numbers are quoted where each figure is used, and the datasheet is linked in the resources box below.
Simulated in Proteus 9.0 SP2, run by us. We built the link ourselves in Proteus 9.0 SP2 Professional (Build 40482): two simulated ATmega328P chips at 16 MHz, one running the sender sketch and one running the receiver sketch with a 16×2 LCD. The LCD alternated between “Cmd: ON” and “Cmd: OFF” with the sequence number rising and the bad-frame counter staying at 0, and a virtual terminal on the receiver’s TX line showed the acknowledgements. The Mega sketch and the push-button sketch were compiled but not simulated. See the screenshots and download the files.
- Three wires are enough: TX to RX, RX to TX, and GND to GND. Crossing TX and RX is the step people miss.
- Both boards must use the same baud rate. 9600 is a safe first choice because it is only 0.2% off at 16 MHz.
- Send framed messages (
<ON,3>), not bare bytes, so a missed byte never leaves the two boards out of step. - Keep both boards at 5 V logic, or use a level shifter. Disconnect the wires on D0 and D1 while uploading to an Uno.
Our Proteus simulation: schematic, screenshots and files
We ran the sender and receiver sketches from this page in Proteus 9.0 SP2 Professional on two simulated ATmega328P chips at 16 MHz, with an LM016L 16×2 display on the receiver. These are our own screenshots. Click any screenshot to enlarge it. The sender sends one framed command per second, the receiver shows it on the LCD and answers with an acknowledgement.




Zip with both compiled .hex files, both sketches, the Proteus project (.pdsprj) and a README. Open the .pdsprj in Proteus 9.0 SP2 or newer, check each chip’s Program File path points to its .hex, and press Play.
What this proves: the framing logic, the parser and the two-way exchange at 9600 baud. What it does not: real Arduino boards, USB, cable length, noise, or 3.3 V and 5 V level differences. Both chips are ideal 5 V logic in the simulation, and a bare ATmega328P at 16 MHz stands in for each Uno (Proteus has no Uno part).
How a serial link works
The Arduino Uno has one hardware serial port (UART). Its two pins are RX (pin D0, which receives) and TX (pin D1, which transmits) (datasheet p. 97). A UART link has no clock wire, so each side has to agree on the speed in advance. That agreed speed is the baud rate. Each character travels as a frame: one start bit, eight data bits and one stop bit in the default 8N1 setting (datasheet p. 183). The line sits high when idle, the start bit pulls it low, and that falling edge is what lets the receiver find where a character begins.
Because TX is an output and RX is an input, the two boards are wired crossed: the TX of one goes to the RX of the other. Joining TX to TX connects two outputs and nothing is received. The grounds must also be joined, because the voltages on the signal wires are measured against ground and the boards need a shared reference.
What you need
Two USB cables
Three male-to-male jumper wires
16×2 HD44780 LCD (receiver display, optional)
10 k potentiometer (LCD contrast)
Breadboard
The two boards can be any mix of 5 V Arduino boards that have a hardware serial port. The LCD only makes the result easy to see on the receiver; the link works without it, and you can read the receiver on the Serial Monitor instead (but see the USB warning below, because the Uno has only one hardware port).
Wiring
Connection table
| Sender | Receiver | What it does |
|---|---|---|
| TX (D1) | RX (D0) | Commands from sender to receiver |
| RX (D0) | TX (D1) | Acknowledgements back from receiver to sender |
| GND | GND | Shared reference for the signals |
| Not connected | LCD: RS to D2, E to D3, D4 to D7 on D4 to D7 | Receiver display (the same wiring as in the Proteus run); VSS and RW to GND, VDD to 5 V, V0 to the middle pin of a 10 k pot |
Four details that stop this working
Choosing the baud rate
Both sketches must call Serial.begin() with the same number. The microcontroller makes the baud rate by dividing its 16 MHz clock, and the divider has to be a whole number, so some speeds come out slightly off. A small error is fine, a large one corrupts characters. These are the datasheet figures for a 16 MHz clock (datasheet p. 199):
| Baud rate | UBRR (U2X = 0) | Error | UBRR (U2X = 1) | Error |
|---|---|---|---|---|
| 9600 | 103 | 0.2% | 207 | 0.2% |
| 19200 | 51 | 0.2% | 103 | 0.2% |
| 38400 | 25 | 0.2% | 51 | 0.2% |
| 57600 | 16 | 2.1% | 34 | -0.8% |
| 115200 | 8 | -3.5% | 16 | 2.1% |
| 250000 | 3 | 0.0% | 7 | 0.0% |
The Arduino core chooses these settings for you when you call Serial.begin(). The point of the table is the pattern: 9600, 19200 and 38400 are 0.2% off and always safe, while 115200 is 3.5% off with the normal divider and 2.1% off with the double-speed bit (U2X) set (datasheet p. 201). Two boards with the same 3.5% error still talk to each other, but a board with a different clock or a longer cable has less room for it. Start at 9600, and raise it only if you need the speed.
Why every message needs a start and an end marker
The simplest possible link sends five bytes, “Hello”, and the receiver waits until five bytes have arrived. It works until it does not: if the receiver is switched on halfway through a message, or one byte is lost, every later message is shifted by one or more characters and nothing in the data tells the receiver it is out of step. A start marker and an end marker solve this. The sender wraps each message as <COMMAND,SEQ>. The receiver throws away everything until it sees <, collects characters until it sees >, and then handles the whole message. A broken message affects only itself, because the next < always restarts the parse.
For comparison, this is the fixed-length version, with no markers. We compiled both halves, but we did not simulate them, and we recommend the framed version below for anything you want to rely on.
// duino4projects.com
// Simplest serial link: sends the five bytes "Hello" once per second. No start or end marker.
char message[5] = {'H', 'e', 'l', 'l', 'o'};
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.write(message, 5);
delay(1000);
}
// duino4projects.com
// Simplest serial link, receiver. Waits for five bytes and prints them. If it starts listening in the
// middle of a message, every later message is shifted, because there is no marker to resynchronise on.
char message[6];
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() >= 5) {
Serial.readBytes(message, 5);
message[5] = '\0';
Serial.println(message);
}
}
The code: framed sender and receiver
The sender uses millis() instead of delay() so it stays free to read replies. It sends <ON,0>, then <OFF,1>, then <ON,2> and so on, once per second, and discards the acknowledgements it gets back. This is the sketch we ran in Proteus on the sender chip.
Sender
// duino4projects.com
// Serial link, sender board. Sends one framed command per second: <ON,0> <OFF,1> <ON,2> ...
// Wiring: sender TX (D1) to receiver RX (D0), sender RX (D0) to receiver TX (D1), GND to GND.
const unsigned long INTERVAL_MS = 1000;
unsigned long lastSent = 0;
bool ledOn = false;
byte seq = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
if (millis() - lastSent >= INTERVAL_MS) {
lastSent = millis();
ledOn = !ledOn;
Serial.print('<');
Serial.print(ledOn ? F("ON") : F("OFF"));
Serial.print(',');
Serial.print(seq++);
Serial.print('>');
}
while (Serial.available() > 0) {
Serial.read(); // replies (<ACK,n>) are ignored here; read them to keep the buffer empty
}
}
The receiver is a small state machine. inFrame says whether it is between markers. A < always resets the buffer. Anything outside the markers is ignored. A frame longer than 12 characters is dropped and counted as bad. A valid ON or OFF frame switches the on-board LED (D13), updates the display and sends <ACK,n> back. This is the sketch we ran on the receiver chip.
Receiver with LCD
// duino4projects.com
// Serial link, receiver board. Reads frames <COMMAND,SEQ>, shows the result on a 16x2 LCD,
// switches the on-board LED (D13) and answers with <ACK,SEQ>.
// LCD: RS D2, E D3, D4 to D7 on D4 to D7. Serial (D0, D1) is the link to the sender.
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
const byte MAX_FRAME = 12; // longest payload we accept, in characters
char frame[MAX_FRAME + 1];
byte length = 0;
bool inFrame = false;
unsigned int goodCount = 0;
unsigned int badCount = 0;
void showStatus(const char *cmd, int seq) {
lcd.setCursor(0, 0);
lcd.print("Cmd: ");
lcd.print(cmd);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print("Seq:");
lcd.print(seq);
lcd.print(" Bad:");
lcd.print(badCount);
lcd.print(" ");
}
void handleFrame() {
char *comma = strchr(frame, ',');
if (comma == NULL) { badCount++; return; }
*comma = '\0';
int seq = atoi(comma + 1);
if (strcmp(frame, "ON") == 0) {
digitalWrite(LED_BUILTIN, HIGH);
} else if (strcmp(frame, "OFF") == 0) {
digitalWrite(LED_BUILTIN, LOW);
} else {
badCount++;
return;
}
goodCount++;
showStatus(frame, seq);
Serial.print(F("<ACK,"));
Serial.print(seq);
Serial.print('>');
}
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
lcd.begin(16, 2);
lcd.print("Waiting...");
Serial.begin(9600);
}
void loop() {
while (Serial.available() > 0) {
char c = Serial.read();
if (c == '<') { // start marker: always restart, so a broken frame never blocks the next one
inFrame = true;
length = 0;
} else if (inFrame && c == '>') {
frame[length] = '\0';
inFrame = false;
handleFrame();
} else if (inFrame) {
if (length < MAX_FRAME) {
frame[length++] = c;
} else {
inFrame = false; // too long: drop it
badCount++;
}
} // anything outside <...> is ignored
}
}
What you should see: the LCD says “Waiting…” for a moment, then line 1 alternates between “Cmd: ON” and “Cmd: OFF” every second and line 2 shows “Seq:” counting up with “Bad:0”. The on-board LED on pin 13 follows the command. In the simulation the LED is not drawn, but the display and the replies matched.
Variations
Arduino Mega as the sender
A Mega has four hardware serial ports, so it can talk to another board and still keep USB free for the Serial Monitor. The Mega’s second port, Serial1, uses TX1 on pin 18 and RX1 on pin 19. Wire Mega pin 18 to the Uno RX (D0), Mega pin 19 to the Uno TX (D1), and GND to GND. Type on or off in the Mega’s Serial Monitor; the Mega sends the same framed message to the Uno running the receiver sketch above and prints the replies. We compiled this sketch for the Mega, but we did not simulate it.
// duino4projects.com
// Arduino Mega as sender on its second serial port (Serial1: TX1 pin 18, RX1 pin 19).
// USB (Serial) stays free for the Serial Monitor. Type on or off in the monitor.
// Wiring: Mega TX1 (18) to Uno RX (0), Mega RX1 (19) to Uno TX (1), GND to GND.
byte seq = 0;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
static String line;
while (Serial.available() > 0) {
char c = Serial.read();
if (c == '\n' || c == '\r') {
line.trim();
line.toUpperCase();
if (line == "ON" || line == "OFF") {
Serial1.print('<');
Serial1.print(line);
Serial1.print(',');
Serial1.print(seq++);
Serial1.print('>');
Serial.print(F("Sent: "));
Serial.println(line);
}
line = "";
} else {
line += c;
}
}
while (Serial1.available() > 0) {
Serial.write(Serial1.read()); // show the receiver's <ACK,n> replies
}
}
Two push buttons as the sender
To send a command by hand instead of on a timer, put two push buttons on the sender. Each button goes between a pin and GND, and the internal pull-up resistor does the rest, so no extra resistors are needed. The sketch sends one frame per press, not one per loop pass. It is a plain bounce guard (a 20 ms delay), not a full debounce routine, which is enough for this demonstration. We compiled it for the Uno, but we did not simulate it.
// duino4projects.com
// Serial link, sender board with two push buttons. Press the ON button to send <ON,n>, the OFF button to send <OFF,n>.
// Buttons: one leg to the pin, the other leg to GND (internal pull-up is used, no resistor needed).
// Wiring: ON button on D8, OFF button on D9. Sender TX (D1) to receiver RX (D0), GND to GND.
const byte PIN_ON = 8;
const byte PIN_OFF = 9;
byte seq = 0;
bool lastOn = HIGH;
bool lastOff = HIGH;
void sendFrame(const __FlashStringHelper *cmd) {
Serial.print('<');
Serial.print(cmd);
Serial.print(',');
Serial.print(seq++);
Serial.print('>');
}
void setup() {
pinMode(PIN_ON, INPUT_PULLUP);
pinMode(PIN_OFF, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
bool nowOn = digitalRead(PIN_ON);
bool nowOff = digitalRead(PIN_OFF);
if (lastOn == HIGH && nowOn == LOW) sendFrame(F("ON")); // send once per press, not while held
if (lastOff == HIGH && nowOff == LOW) sendFrame(F("OFF"));
lastOn = nowOn;
lastOff = nowOff;
delay(20); // crude debounce
while (Serial.available() > 0) Serial.read(); // ignore replies
}
UART, I2C or SPI: which link suits you?
| Link | Wires between boards | Good for | Watch out for |
|---|---|---|---|
| UART (this page) | 2 data wires plus GND | Two boards talking to each other, simple text commands | One partner per port; same baud rate on both sides |
| I2C | 2 shared wires (SDA, SCL) plus GND | Several devices on the same two wires, each with its own address | Slower than SPI, short cables, pull-up resistors may be needed |
| SPI | 3 shared wires plus one select line per device, plus GND | Speed, such as displays, SD cards and fast sensors | More wires; one chip-select pin for every extra device |
If you only need two boards to exchange short messages, UART is the simplest. If one controller needs to talk to many devices, I2C saves wires. If you need speed, use SPI.
If it does not work
| What you see | Likely cause | What to do |
|---|---|---|
| Nothing arrives | TX wired to TX, or a missing ground | Swap the two data wires and check the GND wire |
| Garbled characters | Different baud rate in the two sketches | Use the same number in both Serial.begin() calls |
| Upload fails or times out | Wires still on D0 and D1 | Unplug them while uploading, then reconnect |
| Works, then loses sync | No markers on the messages | Use the framed format on this page |
| Receiver shows “Bad” rising | Frame too long, or noise on a long wire | Check the wire length and the maximum frame size in the receiver |
| Nothing on the Serial Monitor of the receiver | The Uno has one port, shared with USB | Use the LCD on the receiver, or a Mega on one side |
Project variants: two boards talking to each other
- How to establish UART communication between ATmega8 and Arduino Uno?: UART communication between an ATmega8 and an Arduino Uno
- Computer controlled RC car with two Arduinos: a computer-controlled RC car with two Arduinos
Related projects: other links between boards
- Radio link between two Arduino boards: a radio link between two Arduino boards
- Cheap wireless transmission between two Arduinos with Infrared: infrared wireless transmission between two Arduinos
- Long Range, 1.8km, Arduino to Arduino Wireless Communication With the HC-12.: long range Arduino to Arduino wireless with the HC-12
Quick answers
Check your own build
Upload the receiver sketch to the board with the LCD and the sender sketch to the other board, then reconnect the three wires and power both boards. Within a second or two the LCD should alternate between “Cmd: ON” and “Cmd: OFF” with the sequence number going up and “Bad:0”. If it stays on “Waiting…”, swap the two data wires and check the ground wire. If “Bad” rises, check the wire length and the baud rate in both sketches.
Project resources and downloads
Datasheets and documents for the parts in this build. Page numbers quoted on this page refer to these files.
- 💾 Schematic and simulation files (zip)
Zip. Our circuit schematic as a Proteus project (.pdsprj), the two programs that ran in it and a README, from our run in Proteus 9.0 SP2. - 📄 ATmega328P datasheet (Microchip DS40002061B)
PDF, 653 pages, about 33 MB. The USART chapter: frame formats (page 183), baud rate settings (page 199) and the double-speed bit (page 201). Port D pin functions are on page 97. - 📚 Arduino reference: Serial
Web page. Official documentation of the Serial functions used in the sketches. - 📚 Arduino Mega 2560 documentation
Web page. Board documentation, including the four serial ports used in the Mega variation. - 💾 Arduino code and ready-to-upload programs (zip)
Zip, a few KB. Sender, receiver, Mega sender and push-button sender sketches plus the compiled .hex for the Uno sender and receiver and a README. Open a .ino in the Arduino IDE, pick your board and upload.
Quick Solutions to Questions related to Serial Communication between Two Arduino Boards:
- How do you wire two Arduino boards for serial communication?
Connect TX of one board to RX of the other and RX to TX, and join the grounds of both boards; use three male-to-male jumper wires. - Can one Arduino power another in this setup?
Yes, the article shows connecting 5V from one Arduino to the Vin of the other to power it. - What functions are used to send and receive serial data between Arduinos?
The article uses Serial.write to send data and Serial.readBytes or Serial.read to receive data. - How do you send a simple text message from one Arduino to another?
Define a character array like Mymessage, initialize Serial at 9600, then use Serial.write(Mymessage,5) in loop with a delay. - How does the Arduino Mega control the Uno LED via serial?
The Mega reads commands from Serial Monitor, translates on/off to numeric codes, and sends them over Serial1 to the Uno, which sets pin 13 HIGH or LOW based on received codes. - What baud rate should be used between sender and receiver?
Use the same baud rate on both boards; the examples use 9600. - How can push buttons on a transmitter control LEDs on a receiver?
The transmitter reads button states and Serial.write sends '1' or '2'; the receiver reads Serial and writes HIGH to corresponding LED pins when characters are received. - Does the article provide a simulation option?
Yes, a Proteus simulation is provided so users without hardware can test the project.
