I am using different codes which set different values of baud rate through the Serial.begin() function. Do I need to change the baud rate of the serial monitor to match the initialized value on the code I am running every time, or can I just leave the serial monitor baud rate set at the highest frequency of all my sketches (115200)?
Sometimes yes, and sometimes no.
The majority of Arduino boards are connected to your computer through a USB connection (there are some rare outside cases that use other connections like bluetooth or RS485...). That USB connection can fall into two broad categories:
- A USB to UART adaptor that then connects to a UART on the Arduino's main MCU, and
- A direct USB connection to the main MCU
Type 1 are such boards as the Uno, Mega and Nano. Basically any board that has both a main MCU and a secondary chip that lies between the USB connection and that MCU.
In this case the baud rate in the serial monitor is communicated to the USB interface chip and tells that chip "You are to communicate with the main MCU at this speed". You also then have to have the main MCU communicate with the USB chip at that same speed. So it is imperative that those two speeds match.
In the second case this isn't true. USB itself has no real concept of "baud rate". Instead the baud rate you set is merely a piece of configuration information the device at the end of the USB connection can use for something if it sees fit (what that "something" is, is entirely up to the device). Changing that baud rate has no real effect on the communication. Boards like the Leonardo and the Mini fall into this category. They all have a "U" chip, like the ATMega32U4, which directly talk USB.
So, in short:
- If you have a "Non-U" chip based board with a USB interface chip you must match the baud rates, and
- If you have a "U" chip based board (or some other make of board with a direct USB interface) then the whole concept of baud rate is meaningless1 and it really doesn't matter what the numbers are you choose to use where.
1. 1200 baud is a special case in Arduino USB boards as it is used to trigger the bootloader for uploading new code.