What is the Serial Monitor?
The Serial Monitor is a communication channel between your Arduino and computer. It lets you:
- Print debug messages
- Display sensor values
- Send commands to the Arduino
- Monitor program flow
Setup
void setup() {
Serial.begin(9600); // Start at 9600 baud
}
The number (9600) is the baud rate, which is the speed of communication. Both sides must match.
Printing
Serial.print("Hello "); // Print without newline
Serial.println("World!"); // Print with newline
Serial.println(42); // Print a number
Serial.println(3.14); // Print a float
Serial.println(val, HEX); // Print in hexadecimal
Formatting Output
Serial.print("Temp: ");
Serial.print(temperature);
Serial.print("°C | Light: ");
Serial.print(lightLevel);
Serial.println("%");
// Output: "Temp: 22.5°C | Light: 67%"
Reading Input
if (Serial.available() > 0) {
char incoming = Serial.read();
// or
String message = Serial.readStringUntil('\n');
}
Common Baud Rates
| Rate | Use | |------|-----| | 9600 | Default, most common | | 115200 | Fast, for lots of data |
Tips
- Open the Serial Monitor with Ctrl+Shift+M (or the magnifying glass icon)
- Make sure the baud rate in the monitor matches
Serial.begin() - Use Serial.print() liberally while debugging, then remove when done
- Don't use pins 0 and 1 for I/O when using Serial (they're TX/RX)