Verified by our editorial teamSimulated in Proteus 9.0 SP2

Enhancing Projects with Serial Connectivity Between Arduino Boards

Learn to connect two Arduino boards to send messages and control LEDs with buttons using RX/TX pins and Serial functions.

Avatar of Ibrar Ayyub
By Ibrar Ayyub
Published February 3, 2024
At a glance
CategoryArduino Programmer Projects
DifficultyIntermediate
IncludesCode, Diagrams, Datasheets
UpdatedNovember 24, 2026
Reading timeabout 16 min
On this page

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)
16 min read

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.

HOW THIS PAGE WAS CHECKED

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.

IN SHORT
  • 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.
3 wires
TX, RX and GND
9600 baud
first test speed
0.2%
baud error at 16 MHz
2 boards
sender and receiver

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.

Proteus 9.0 SP2 schematic: sender ATmega328P, receiver ATmega328P with a 16x2 LCD, running
Our Proteus schematic with the simulation running. Top chip: sender. Lower chip: receiver, with the LCD above it. The two serial lines are joined with wire labels.
Proteus LCD showing Cmd: ON and a sequence number with Bad:0
Receiver LCD after an ON frame: command and sequence number, no bad frames.
Proteus LCD showing Cmd: OFF and a sequence number with Bad:0
A second later: the next frame is OFF and the sequence number has moved on.
Proteus virtual terminal showing the replies ACK,0 ACK,1 ACK,2 next to the LCD showing Cmd: ON
A virtual terminal on the receiver’s TX line shows the acknowledgements coming back: <ACK,0><ACK,1><ACK,2>. The LCD in the corner shows the matching frame.
💾 Download our simulation files (serial-link-proteus-files.zip)
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 Arduino Uno boards (or one Uno and one Mega)
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

Sender (Uno) Receiver (Uno) TX (D1)RX (D0)GND RX (D0)TX (D1)GND TX goes to RX: the two data wires cross Common ground

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

USB and the wires share D0 and D1. On an Uno the USB chip is connected to the same two pins. Unplug the jumper wires from D0 and D1 while you upload a sketch, then plug them back in. A wire left on D0 or D1 is the most common reason an upload fails with a link attached.
TX to RX, not TX to TX. If nothing arrives, swap the two data wires first. It is the cheapest fix and the most common mistake.
Join the grounds. Two boards powered from two USB ports can sit at slightly different voltages. Without a ground wire the signal levels are meaningless to the receiver and you see garbage or nothing.
Mixing 5 V and 3.3 V boards needs a level shifter. An Uno sends 5 V signals. A 3.3 V board (many ESP and ARM boards) can be damaged by a 5 V signal on its RX pin. Use a level shifter or a resistor divider on the line going from the 5 V board to the 3.3 V board.

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.

The sequence number is optional but useful. It rises by one with every message, so the receiver (and you, on the LCD) can see at once if messages are being lost. The receiver in this page also counts messages it had to reject as “Bad”.

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

Related projects: other links between boards

Quick answers

How do I connect two Arduino boards with serial?
Connect the TX pin of each board to the RX pin of the other, and join the two grounds. On an Uno, TX is pin D1 and RX is pin D0.
Can I use any baud rate?
Both sides must use the same one. 9600 is a safe default. At a 16 MHz clock, 9600, 19200 and 38400 are 0.2% off; 115200 is 3.5% off with the normal divider.
Why do my uploads fail with the link connected?
On an Uno, pins D0 and D1 also connect to the USB chip. Unplug the link wires from those two pins while uploading.
Can I connect a 5 V Uno to a 3.3 V board?
Not directly. A 5 V signal on a 3.3 V RX pin can damage it. Use a level shifter or a resistor divider on the 5 V to 3.3 V line.
How many boards can share one serial link?
A hardware UART is point to point: one partner per port. A Mega has four ports. For many devices on the same wires, use I2C.
Do I need the sequence number?
No, but it costs almost nothing and shows lost messages immediately.

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.

Share this project
X
LinkedIn
Reddit
WhatsApp

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.
Scroll to Top