Sets the data rate in bits per second (baud) for serial data transmission. For communicating with Serial Monitor, make sure to use one of the baud rates listed in the menu at the bottom right corner of its screen. You can, however, specify other rates - for example, to communicate over pins 0 and 1 with a component that requires a particular baud rate.
An optional second argument configures the data, parity, and stop bits. The default is 8 data bits, no parity, one stop bit.
- Serial: serial port object. See the list of available serial ports for each board on the Serial main page.
- speed: in bits per second (baud). Allowed data types: long.
- config: sets data, parity, and stop bits. Valid values are:
- SERIAL_8N1 (the default)
- SERIAL_5E1: even parity
- SERIAL_5O1: odd parity
The result on Serial Monitor:
Arduino Mega example:
Thanks to Jeff Gray for the mega example
※ NOTES AND WARNINGS:
- For USB CDC serial ports (e.g. Serial on the Leonardo), Serial.begin() is irrelevant. You can use any baud rate and configuration for serial communication with these ports. See the list of available serial ports for each board on the Serial main page.
The only config value supported for Serial1 on the Arduino Nano 33 BLE and Nano 33 BLE Sense boards is SERIAL_8N1.
- Serial functions are not only used for the communication between an Arduino board and Serial Monitor of Arduino IDE but also used for the communication between:
- An Arduino board and other Arduino board
- An Arduino board and other sensors/devices
- An Arduino board and computer (any Serial software on computer)