Serial.println()

Description

Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n').

Serial.println() is the same as Serial.print(), except for one thing: Serial.println() prints '\r' and '\n' character at the end while Serial.print() does not.

Syntax

Serial.println(val)

Serial.println(val, format)

Parameter Values

  • Serial: serial port object. See the list of available serial ports for each board on the Serial main page.
  • val: the value to print. Allowed data types: any data type.
  • format: (optional) specifies:

Return Values

  • println() returns the number of bytes written, though reading that number is optional. Data type: size_t.

Example Code

void setup() { // open the serial port at 9600 bps: Serial.begin(9600); // print a character Serial.println('N'); // print a string Serial.println(); // print an empty line Serial.println("ArduinoGetStarted.com"); // print a float number float a = 1.23456; Serial.println(); // print an empty line Serial.println(a); // 2 decimal places by default Serial.println(a, 4); // 4 decimal places Serial.println(a, 5); // 5 decimal places Serial.println(a, 6); // 6 decimal places // print an interger number out in many formats: int x = 77; Serial.println(); // print an empty line Serial.println(x); // print as an ASCII-encoded decimal by default Serial.println(x, DEC); // print as an ASCII-encoded decimal Serial.println(x, HEX); // print as an ASCII-encoded hexadecimal Serial.println(x, OCT); // print as an ASCII-encoded octal Serial.println(x, BIN); // print as an ASCII-encoded binary } void loop() { }

The result on Serial Monitor:

COM6
Send
N ArduinoGetStarted.com 1.23 1.2346 1.23456 1.234560 77 77 4D 115 1001101
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

※ NOTES AND WARNINGS:

  • For information on the asyncronicity of Serial.println(), see the Notes and Warnings section of the Serial.write() reference page.
  • Serial functions are not only used for the communication between an Arduino board and Serial Monitor of Arduino IDE but also used for the communication between:
  • An Arduino board and other Arduino board
  • An Arduino board and other sensors/devices
  • An Arduino board and computer (any Serial software on computer)

See Also

ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables.

※ OUR MESSAGES