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'). This command takes the same forms as Serial.print().

Syntax

  • Serial.println(val)
  • Serial.println(val, format)

Parameters

  • 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
    : specifies the number base (for integral data types) or number of decimal places (for floating point types).

Returns

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

Example Code

1/*
2 Analog input reads an analog input on analog in 0, prints the value out.
3 created 24 March 2006
4 by Tom Igoe
5 */
6
7 int analogValue = 0; // variable to hold the analog value
8
9 void setup() {
10 // open the serial port at 9600 bps:
11 Serial.begin(9600);
12 }
13
14 void loop() {
15 // read the analog input on pin 0:
16 analogValue = analogRead(0);
17
18 // print it out in many formats:
19 Serial.println(analogValue); // print as an ASCII-encoded decimal
20 Serial.println(analogValue, DEC); // print as an ASCII-encoded decimal
21 Serial.println(analogValue, HEX); // print as an ASCII-encoded hexadecimal
22 Serial.println(analogValue, OCT); // print as an ASCII-encoded octal
23 Serial.println(analogValue, BIN); // print as an ASCII-encoded binary
24
25 // delay 10 milliseconds before the next reading:
26 delay(10);
27 }

Notes and Warnings

For information on the asyncronicity of

Serial.println()
, see the Notes and Warnings section of the Serial.write() reference page.

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.