Serial.println()

Description

Prints data to 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 same forms as Serial.print() .

Syntax

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

Parameters

Serial : serial port object. See list of available serial ports for each board on Serial main page .
val : value to print. Allowed data types: any data type.
format : specifies number base (for integral data types) or number of decimal places (for floating point types).

Returns

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

Example Code

/*H********************************************************************
 ANALOG INPUT READS AN ANALOG INPUT ON ANALOG IN 0, PRINTS VALUE OUT.
 CREATED 24 MARCH 2006 BY Tom Igoe
**********************************************************************/

int analogValue = 0;                        // VARIABLE TO HOLD ANALOG VALUE

/*F********************************************************************
*
**********************************************************************/
void 
setup() 
{
	Serial.begin( 9600 );                    // OPEN SERIAL PORT AT 9600 BPS
}
/*F********************************************************************
*
**********************************************************************/
void 
loop() 
{
	analogValue = analogRead( 0 );             // READ ANALOG INPUT ON PIN 0

	// print it out in many formats:
	Serial.println( analogValue);           // PRINT AS AN ASCII-ENCODED DEC
	Serial.println( analogValue, DEC);      // PRINT AS AN ASCII-ENCODED DEC
	Serial.println( analogValue, HEX);      // PRINT AS AN ASCII-ENCODED HEX
	Serial.println( analogValue, OCT);      // PRINT AS AN ASCII-ENCODED OCT
	Serial.println( analogValue, BIN);      // PRINT AS AN ASCII-ENCODED BIN

	delay( 10 );               // DELAY 10 MILLISECONDS BEFORE NEXT READING
}

Notes and Warnings

For information on asyncronicity of Serial.println() , see Notes and Warnings section of Serial.write() reference page .