Skip to content

Communication using serial


In this tutorial you will learn how to read data from serial char by char, sentence by sentence or in more complex chunks.

Table of contents:


Serial, bauds and bytes

Todo (id=no todo id): What serial is
Todo (id=no todo id): Serial vs parallel
Todo (id=no todo id): Why serial over parallel

Bod (Baud), named after Émile Baudot [bo:do] -- the creator of the Baudot telegraph code and abbreviated as Bd, is a measure that specifies the speed of transmission of changes in the transmission medium. Every change is called a character. The carrier signal is characterized by the number of signal intervals, or pulses, that are transmitted per second. Each pulse is called a baud. For example, a transmission speed of 250 Bd means that the signal can change 250 times in every second. If you ask: How many bits is it equal to?, the answer is: Nobody knows. Really. It is strictly dependent on the medium and coding you use. Technically, the baud rate specifies the number of symbols per second; rather than bits. Each symbol can represent (transport) one or more bits of data.

Although the terms baud and bps (bits per second) are often used interchangably, the two are not the same at all. Bps is a measure of how many bits can be transmitted during one pulse (one baud). So,

The Bd should not be confused with the data rate (measured in bits per second) because each change in the signal may carry information about one or more bits (e.g. for 16-QAM it is 4 bits). When each change in signal carries only one bit information, then the number of bauds is equal to the data rate. Probably the misunderstanding of the concept of bod comes from the times when each change in the signal carried information about only 1 bit.

A good example illustrating the difference between the speed expressed in bauds and in bits per second is a man using a single flag. He can change his hand position once every second, so his rate of change of signal (baud) is 1 per second. Assume, that the flag can be held in one of eight positions "arround": up, left-up, left, left-down, down, right-down, right, down-right. This means that each signal carries information about three bits (8 different flag positions can be written on three bits), so the data transmission speed in this case is 3 bits per second.

In case ot typical 8-N-1 (8 data bits, no parity, and 1 stop bit + 1 start bit which is always present) serial communication at 9600 baud about 960 characters per second arrive to Arduino, which means there is a gap of just over 1 millisecond between characters. Is that fast? Is that a lot? Not too much, not too fast. The Arduino can do a lot in 1 millisecond. Even at 115200 baud there is still 86 microseconds between characters. Please keep in mind that during 86 microseconds Arduino executes 1376 instructions.

In Arduino supported baud rates are 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 38400, 57600, and 115200.


Reading one character

Keep in mind that the Arduino buffer size is 64 bytes.


Reading sequence of characters


With end marker

But if you try read this abc@def you will only see the first part abc. Then if you send ghi@ you will see defghi because the Arduino has no idea that should ignore def part.


Enclosed with markers


Reading integers enclosed with markers


Reading complex data

Sending binary data