Serial.println(data)

Description

Prints a data to the serial port, 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():

Serial.println(b) prints b as a decimal number in an ASCII string followed by a carriage return and a linefeed.

Serial.println(b, DEC) prints b as a decimal number in an ASCII string followed by a carriage return and a linefeed.

Serial.println(b, HEX) prints b as a hexadecimal number in an ASCII string followed by a carriage return and a linefeed.

Serial.println(b, OCT) prints b as an octal number in an ASCII string followed by a carriage return and a linefeed.

Serial.println(b, BIN) prints b as a binary number in an ASCII string followed by a carriage return and a linefeed.

Serial.print(b, BYTE) prints b as a single byte followed by a carriage return and a linefeed.

Serial.println(str) if str is a string or an array of chars, prints str an ASCII string.

Serial.println() just prints a carriage return and a linefeed.

Parameter

data types: integer types, including char, strings (char arrays) & floats
Printing of floats is supported with a precision of two places to the right of the decimal point.
This may change soon.

Returns

None

Example:

/*
  Analog input

 reads an analog input on analog in 0, prints the value out.

 created 24 March 2006
 by Tom Igoe
 */

int analogValue = 0;    // variable to hold the analog value

void setup() {
  // open the serial port at 9600 bps:
  Serial.begin(9600);
}

void loop() {
  // read the analog input on pin 0:
  analogValue = analogRead(0);

  // print it out in many formats:
  Serial.println(analogValue);       // print as an ASCII-encoded decimal
  Serial.println(analogValue, DEC);  // print as an ASCII-encoded decimal
  Serial.println(analogValue, HEX);  // print as an ASCII-encoded hexadecimal
  Serial.println(analogValue, OCT);  // print as an ASCII-encoded octal
  Serial.println(analogValue, BIN);  // print as an ASCII-encoded binary
  Serial.println(analogValue, BYTE); // print as a raw byte value

  // delay 10 milliseconds before the next reading:
  delay(10);
}

Programming Tip / Known Issues

see Serial.print

See also

Reference Home