Arduino - Println

Arduino

Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

Blog » | Forum » | Playground »

## 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.

#### Parameters

b: the byte to print, or

str: the string to print

#### 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.print(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

- ASCII chart
- Serial.begin(speed)
- Serial.available()
- Serial.read()
- Serial.print(data)

Reference Home

Edit Page | Page History | Printable View | All Recent Site Changes