Learn / Communication / Serial basics

Serial Communication Basics

ReviewedBeginnerFreeAbout 6 min
NRF24
In short

Serial Communication Basics: the short answer

Serial (UART) is the simplest way for two devices to talk. Each byte is sent one bit at a time on a single wire: a start bit, eight data bits and a stop bit, which is called 8N1. Example: About 54 ms. At 115200 baud the same line takes about 4.5 ms, which is why fast loops should use the higher speed.

Level
Beginner
Time
About 6 min
Topic
Communication
You will learn to

Send and receive text over serial between a board and your computer, and wire two boards together correctly.

Before this: Arduino and ESP32 Basics

Serial (UART) is the simplest way for two devices to talk. Each byte is sent one bit at a time on a single wire: a start bit, eight data bits and a stop bit, which is called 8N1. Both sides must agree on the speed, called the baud rate, such as 9600 or 115200 bits per second. If they do not match, you see random symbols instead of text.

When you call Serial.begin(115200) on an Arduino or ESP32 and open the Serial Monitor at the same speed, the board's USB chip carries the serial data to your computer. Serial.println() sends text, and Serial.available() and Serial.read() receive what you type. It is the first debugging tool for every project.

To connect two boards or a board and a module directly, three wires are needed: TX of one goes to RX of the other, RX to TX (crossed over), and the grounds are connected together. Without a shared ground the signals have no reference and will not work. Check the voltage levels: a 5 V Arduino's TX can damage a 3.3 V ESP32's RX, so use a level shifter or a simple divider, for example 1 kΩ and 2 kΩ.

What actually travels on the wire

An idle UART line sits high. A byte begins with a start bit (low), then eight data bits, the least significant first, then a stop bit (high). At 9600 baud each bit lasts about 104 µs, so a 10-bit frame takes about 1.04 ms and carries 960 bytes per second at most. At 115200 baud that rises to about 11.5 kB/s.

Neither side sends a clock. Each side times the bits by itself, so the baud rates must agree to within a few percent; a mismatch shows up as garbage characters or as framing errors.

Debugging with the Serial Monitor

Print what the program does at each stage: raw sensor value, converted value, state of the program. If the monitor shows nothing, check the baud rate, the port, and that Serial.begin() is called in setup. If it shows odd symbols, the baud rate differs. Some boards print a short burst of garbage at reset before your sketch starts; that is the boot loader and is normal.

Printing takes time. Sending long text inside a fast loop slows everything down. Print only when a value changes, or at a fixed interval, and remove debug prints from time-critical code.

Wiring two devices

Cross the data lines: one's TX goes to the other's RX. Connect the grounds. Match voltage levels: 3.3 V logic into a 5 V Uno input usually works, but 5 V into a 3.3 V ESP32 pin does not. A resistor divider of 1 kΩ and 2 kΩ is enough for a slow signal; use a level shifter for fast ones.

Do not connect the same pins to the USB serial chip and another device at the same time. On an Uno, pins 0 and 1 are shared with USB, so a module wired there can block uploads. Use SoftwareSerial or, on an ESP32, a second hardware UART.

Beyond text: sending data reliably

Text lines ending in a newline are easy to read and debug, for example "T=24.5,H=61". To send binary data, add a start marker, a length and a checksum, so the receiver can tell where a message begins and discard a damaged one. Read bytes into a buffer until you see the end of the line, and handle a partial line instead of assuming the whole message has arrived.

Common mistakes
  • Connecting TX to TX and RX to RX.
  • Forgetting a common ground between two boards.
  • Assuming Serial.read() returns a whole line. It returns one byte at a time.
Worked example

How long does it take to send a 50-character line at 9600 baud?

  1. 8N1 uses 10 bits per byte (start, 8 data, stop).
  2. 9,600 ÷ 10 = 960 bytes per second.
  3. 50 characters plus newline is about 52 bytes.
  4. 52 ÷ 960 ≈ 54 ms.

Result. About 54 ms. At 115200 baud the same line takes about 4.5 ms, which is why fast loops should use the higher speed.

Try it

Write a sketch that reads a line from the Serial Monitor and replies with the line in capital letters. Then change the Serial Monitor speed to a wrong value and note what you see.

Check yourself

3 quick questions

  1. The Serial Monitor shows random symbols. What is the most likely cause?

  2. How do you connect TX and RX between two boards?

  3. How many bytes per second does 115200 baud 8N1 carry?

Common questions

What will I learn in "Serial Communication Basics"?

Send and receive text over serial between a board and your computer, and wire two boards together correctly.

How long does it take to send a 50-character line at 9600 baud?

8N1 uses 10 bits per byte (start, 8 data, stop). 9,600 ÷ 10 = 960 bytes per second. 50 characters plus newline is about 52 bytes. 52 ÷ 960 ≈ 54 ms. About 54 ms. At 115200 baud the same line takes about 4.5 ms, which is why fast loops should use the higher speed.

The Serial Monitor shows random symbols. What is the most likely cause?

Wrong baud rate. Both ends must use the same baud rate.

How do you connect TX and RX between two boards?

TX to RX, RX to TX, plus a common ground. Each side's transmitter feeds the other's receiver, and they share ground.

How many bytes per second does 115200 baud 8N1 carry?

11,520. 10 bits per byte: 115,200 ÷ 10 = 11,520.