Sub topic 3
Baud Rate and Bit Timing
Assume you know the basic Arduino setup() and loop() functions, bytes, and digital HIGH and LOW levels. You should also know that UART sends bits over a wire without a shared clock. This chapter explains how both devices keep those bits synchronized.
What baud rate means
The baud rate is the number of signal symbols sent per second. In common UART links, one symbol represents one bit, so baud rate is usually treated as bits per second.
For example:
- At 9,600 baud, one bit lasts about 104.17 microseconds.
- At 115,200 baud, one bit lasts about 8.68 microseconds.
The bit time is calculated as:
bit time = 1 / baud rateUse seconds for the result. To convert seconds to microseconds, multiply by 1,000,000.
A UART receiver uses the start bit to estimate the timing of the incoming frame. It then samples the data bits near their centers. The receiver does not need a separate clock wire, but its clock must be close enough to the transmitter's clock.
Calculating a frame's speed
A UART frame contains more than the data byte. A common format is 8N1:
- 1 start bit
- 8 data bits
- No parity bit
- 1 stop bit
The total is 10 transmitted bits for each 8-bit byte. Therefore, the useful data rate is lower than the baud rate.
frame bits = start bits + data bits + parity bits + stop bits
data bytes per second = baud rate / frame bitsAt 9,600 baud with 8N1:
frame bits = 1 + 8 + 0 + 1 = 10
bytes per second = 9600 / 10 = 960 bytes per secondThis calculation ignores pauses between frames and software overhead. If you add a parity bit, the frame has 11 bits, so the maximum byte rate decreases to about 873 bytes per second.
| Format | Bits per byte | Approximate rate at 9,600 baud |
|---|---|---|
| 8N1 | 10 | 960 bytes/s |
| 8E1 | 11 | 873 bytes/s |
| 8N2 | 11 | 873 bytes/s |
How the receiver samples bits
UART lines are normally idle at a logic HIGH level. A frame begins when the transmitter drives the line LOW for the start bit. The receiver detects this transition and starts its timing process.
The receiver usually samples several times during each bit period. It chooses a sample near the center, where a small timing error is least likely to cause a wrong value. After sampling all data and optional parity bits, it checks the stop bit.
The following flow shows the timing relationship:
The receiver's timing is only an estimate. If its clock runs too quickly or slowly, each sample moves farther from the center as the frame continues. A large enough error causes a data bit or stop bit to be sampled incorrectly.
Choosing and matching a baud rate
Both ends must use the same baud rate and frame format. For example, these settings match:
void setup() {
Serial.begin(115200, SERIAL_8N1);
}
void loop() {
Serial.println(F("UART test"));
delay(1000);
}A connected device must also use 115,200 baud, 8 data bits, no parity, and 1 stop bit. The default Arduino format is commonly SERIAL_8N1, but specifying it makes the setting clear.
A baud mismatch often produces garbled characters. A small mismatch may work for short frames, while a larger mismatch causes framing errors or completely unusable data. Long frames are less tolerant because timing error accumulates across more bits.
Clock error and practical limits
The actual baud rate depends on the microcontroller clock and the UART's divider settings. The selected rate may be approximate rather than exact. For example, a UART may produce a rate slightly above or below the requested value.
The total timing error is the difference between the transmitter and receiver errors. If one side is fast and the other is slow, their errors add. Temperature, supply voltage, and the accuracy of a clock source can also affect timing.
Use lower baud rates when:
- The devices have inaccurate clocks.
- The cable is long or electrically noisy.
- Messages contain many bytes.
- Reliability matters more than speed.
Use higher baud rates when:
- Both devices have accurate clocks.
- The wiring is short and clean.
- The receiver can process bytes quickly.
- The selected physical interface supports the speed.
A timing calculation in Arduino
This sketch prints the bit time and estimated 8N1 byte rate. It uses floating-point arithmetic so the displayed values include decimals.
const unsigned long BAUD = 9600;
const byte FRAME_BITS_8N1 = 10;
void setup() {
Serial.begin(BAUD);
delay(500);
float bitTimeUs = 1000000.0 / BAUD;
float bytesPerSecond = BAUD / (float)FRAME_BITS_8N1;
Serial.print(F("Bit time: "));
Serial.print(bitTimeUs, 2);
Serial.println(F(" us"));
Serial.print(F("Approximate 8N1 rate: "));
Serial.print(bytesPerSecond, 2);
Serial.println(F(" bytes/s"));
}
void loop() {
}At 9,600 baud, the output should be close to 104.17 microseconds per bit and 960 bytes per second.
Exercise
A link uses 19,200 baud with format 8E1. How many bits are transmitted for each byte, and what is the approximate maximum byte rate?
Show answer
The frame has 1 start bit, 8 data bits, 1 parity bit, and 1 stop bit, for 11 bits. The approximate rate is 19,200 / 11 = 1,745 bytes per second.