How to Use Serial Monitor in Arduino: Simple Guide
To use the
Serial Monitor in Arduino, first start serial communication in your code with Serial.begin(baud_rate). Then, use Serial.print() or Serial.println() to send data to the monitor, which you open from the Arduino IDE to see the output.Syntax
The Serial Monitor uses these main commands:
Serial.begin(baud_rate): Starts serial communication at the speed you set (baud rate).Serial.print(data): Sends data to the monitor without a new line.Serial.println(data): Sends data followed by a new line.
The baud rate must match the Serial Monitor's setting to display data correctly.
arduino
void setup() { Serial.begin(9600); // Start serial communication at 9600 baud } void loop() { Serial.println("Hello, Serial Monitor!"); // Print message with new line delay(1000); // Wait 1 second }
Example
This example sends a message every second to the Serial Monitor. It shows how to start communication and print text repeatedly.
arduino
void setup() { Serial.begin(9600); // Initialize serial communication } void loop() { Serial.println("Hello from Arduino!"); // Print message delay(1000); // Pause for 1 second }
Output
Hello from Arduino!
Hello from Arduino!
Hello from Arduino!
... (repeats every second)
Common Pitfalls
Common mistakes when using the Serial Monitor include:
- Not calling
Serial.begin()insetup(), so no data is sent. - Mismatch between the baud rate in code and the Serial Monitor setting, causing garbled output.
- Forgetting to open the Serial Monitor after uploading the code, so you don't see any output.
Always check these to ensure your serial communication works smoothly.
arduino
void setup() { // Wrong: Missing Serial.begin() } void loop() { Serial.println("This won't show up correctly"); delay(1000); } // Correct version: void setup() { Serial.begin(9600); // Correctly start serial communication } void loop() { Serial.println("This will show up"); delay(1000); }
Quick Reference
Here is a quick cheat sheet for Serial Monitor commands and tips:
| Command | Description |
|---|---|
| Serial.begin(baud_rate) | Start serial communication at given speed |
| Serial.print(data) | Send data without new line |
| Serial.println(data) | Send data with new line |
| Serial.available() | Check if data is available to read |
| Serial.read() | Read incoming data |
| Match baud rate | Ensure Serial Monitor baud rate matches code |
| Open Serial Monitor | Use Arduino IDE button or Ctrl+Shift+M |
Key Takeaways
Always start serial communication with Serial.begin() in setup().
Use Serial.print() or Serial.println() to send data to the Serial Monitor.
Match the baud rate in your code and Serial Monitor settings to avoid garbled text.
Open the Serial Monitor after uploading your code to see output.
Use delay() to control how often data is sent for easier reading.