How to Use the Arduino Serial Monitor
In this tutorial, you'll learn about How to Use the Arduino Serial Monitor. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
The Problem
You open the Arduino Serial Monitor and see nothing, garbled characters like ÿÿÿÿÿ, or the port is already in use. The Serial Monitor is essential for debugging, but connection issues prevent you from reading sensor data or debug output.
Quick Fix
Fix 1: Garbled Text (Wrong Baud Rate)
WRONG — Serial Monitor at 9600 baud but sketch uses a different rate:
void setup() {
Serial.begin(115200); // sketch uses 115200
Serial.println("Hello");
}
# Serial Monitor at 9600 baud shows:
# ÿÿÿÿÿHelloÿÿÿÿ
RIGHT — match the baud rate in the Serial Monitor:
# Set the bottom-right dropdown to 115200 baud
# Output:
# Hello
Fix 2: No Output at All
WRONG — calling Serial.print before Serial.begin:
void setup() {
Serial.println("Starting..."); // Serial not initialized yet
Serial.begin(9600);
}
// (no output — begin must be called first)
RIGHT — initialize Serial first:
void setup() {
Serial.begin(9600);
Serial.println("Starting...");
}
// Output:
// Starting...
Fix 3: Port Already in Use
# Error opening serial port '/dev/ttyACM0'. (Port busy)
WRONG — multiple Serial Monitor Windows open:
# (each port can only be opened by one application)
RIGHT — close all other Serial Monitor Windows and applications:
# Check for other applications using the port:
lsof /dev/ttyACM0
# Close the application shown in the output
Fix 4: Serial Monitor Opens but Closes Immediately
# The USB connection resets when the Serial Monitor opens (DTR signal)
RIGHT — add a small delay in setup to stabilize:
void setup() {
Serial.begin(9600);
while (!Serial) { ; } // Wait for Serial Monitor to connect (for Leonardo/Micro)
delay(100); // Allow USB to stabilize
Serial.println("Ready");
}
Fix 5: Line Ending Issues
WRONG — Serial.read() returns nothing because no line ending is sent:
void loop() {
if (Serial.available()) {
char c = Serial.read();
// (using "No line ending" in Serial Monitor — c is received without delimiter)
}
}
RIGHT — set the correct line ending in the Serial Monitor:
# Bottom-right dropdown: choose "Newline", "Carriage return", or "Both NL & CR"
# Match the ending your sketch expects:
# while (Serial.available() == 0) { }
# String data = Serial.readStringUntil('\n');
Fix 6: Serial Plotter Not Working
# (Arduino Serial Plotter only works with numeric values separated by commas or spaces)
WRONG — mixing text and numbers:
Serial.println("Temperature: " + String(temp));
RIGHT — send comma-separated numeric values only:
Serial.print(temp);
Serial.print(",");
Serial.println(humidity);
// Output: 23.5,65.2
Use DodaTech's Serial Analyzer to capture, filter, and visualize serial data for complex debugging scenarios.
Prevention
- Always call
Serial.begin()before anySerial.print(). - Match the baud rate between sketch and Serial Monitor.
- Close unused Serial Monitor Windows.
- Use consistent line endings in your sketch and Serial Monitor.
- Test with a simple "Hello World" sketch before debugging sensors.
Common Mistakes with serial monitor
- Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad - Mixing let bindings with <- bindings in do notation, producing type errors
These mistakes appear frequently in real-world Arduino code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro