HOWTO · Arduino
How to Print New Line in Arduino
Learn how Serial.print() and Serial.println() format Arduino serial output, how to add a line break, and how to print labels and values in a sketch.
On this page
To print a new line in an Arduino sketch, call Serial.println() after the text or value that should end the line. Use Serial.print() when the next value should continue on the same line. You can also pass the newline character \n to Serial.print() to end a line explicitly. Start serial communication with Serial.begin(9600) in setup() before sending data.
Use Serial.println() to end a line
Serial.println() writes its argument and then a line ending. Each call therefore starts the next output after the previous line has ended. This is useful for separate readings, status messages, and other values that are easier to read one per line.
The following standalone C++ example uses a small Serial stand-in so its captured text can be checked without an Arduino board. On a board, the Arduino core supplies Serial and calls setup(); the sketch calls shown here are the same ones to use there. Run this example:
#include <cassert>
#include <string>
class SerialPort {
public:
std::string data;
void begin(unsigned long) {}
void print(const char* value) { data += value; }
void print(char value) { data += value; }
void println(const char* value) { data += value; data += '\n'; }
void println(int value) { data += std::to_string(value); data += '\n'; }
};
SerialPort Serial;
void setup() {
Serial.begin(9600);
Serial.println("Arduino is ready");
}
int main() {
setup();
assert(Serial.data == "Arduino is ready\n");
}
The stand-in records text and the assertion checks that println() appends a line ending. This is a C++ model of the calls, not firmware for a board. The supplied runtime case passed with exit code 0 and empty stdout: the assertion checks the captured text without displaying it to stdout.
Add a line ending with Serial.print()
Serial.print() leaves the output cursor after the characters it writes. To end that line explicitly, pass the newline character \n as a character literal after the preceding text. In a sketch, the calls are Serial.print("Arduino is ready"); followed by Serial.print('\n');. The first writes the message; the second writes a line break.
In C++, single quotes denote a character such as '\n', while double quotes denote a string such as "Arduino is ready". This distinction matters: a newline character is one character, and "\n" is a string containing that character.
Print multiple values across lines
You can combine calls to place a label and a value together, then end the line with Serial.println(). For example, use Serial.print("Temperature: "); followed by Serial.println(temperature);, then repeat with Serial.print("Humidity: "); and Serial.println(humidity);. Declare the values, such as int temperature = 25; and int humidity = 60;, in the sketch before using them.
Each Serial.print() writes a label without ending the line. The following Serial.println() writes the variable value and ends that line. Passing a variable directly is supported; numeric formatting choices are separate from line-break behavior. These additional calls are shown inline rather than as a second program, so the article makes no execution claim for them.
Choose the right method for serial output
Use Serial.println(value) when each message or reading should occupy its own line. Use Serial.print(value) to build one line from several pieces, then call Serial.println() or Serial.print('\n') when the line is complete. Serial.begin(9600) belongs in setup() so serial communication is initialized before the sketch writes to the serial port.
A practical pattern is to print a label with Serial.print(), print its value with Serial.println(), and repeat for the next reading. This keeps labels and values together while making successive readings easier to scan in the Serial Monitor. The supplied execution case for the standalone C++ model passed with exit code 0 and empty stdout; it validates captured text with an assertion rather than displaying text to stdout.