Serial Print Values

Description

Prints data to the serial port as human-readable ASCII text. This command can take many forms. Numbers are printed using an ASCII character for each digit. Floats are similarly printed as ASCII digits, defaulting to two decimal places. Bytes are sent as a single character. Characters and strings are sent as is. For example-

Serial.println((float)(2.789),1); // This will print: “2.8” The 2.789 is the floating value that you want to print and the 1 after the comma is the number of decimal value you would like to display. 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'). Aug 08, 2011  A Better Serial.print For Arduino Posted on August 8, 2011 by David Pankhurst In a previous article I described how to add the old-fashioned print function to Arduino to improve debugging – after all, it gets tedious to use a separate Serial.print function for each type – and inserting information into a string is printf’s specialty. Use Serial.print to display Arduino output on your computer monitor: Part 2. The print statement is interpreting this as an integer (16bits) instead of two 8 bit characters because in C the character literal is defined as an int and your providing just the right number of 8. Sep 03, 2013  How to get the Serial Monitor to display values in columns? I've got an Air Quality sensor and a Light sensor running off the arduino. However, when I open the Serial Monitor the results just alternate between the two in one single column.

  • Serial.print(78) gives '78'

  • Serial.print(1.23456) gives '1.23'

  • Serial.print('N') gives 'N'

  • Serial.print('Hello world.') gives 'Hello world.'

An optional second parameter specifies the base (format) to use; permitted values are BIN(binary, or base 2), OCT(octal, or base 8), DEC(decimal, or base 10), HEX(hexadecimal, or base 16). For floating point numbers, this parameter specifies the number of decimal places to use. For example-

  • Serial.print(78, BIN) gives '1001110'

  • Serial.print(78, OCT) gives '116'

  • Serial.print(78, DEC) gives '78'

  • Serial.print(78, HEX) gives '4E'

  • Serial.print(1.23456, 0) gives '1'

  • Serial.print(1.23456, 2) gives '1.23'

  • Serial.print(1.23456, 4) gives '1.2346'

Serial Print 2 Values Arduino

You can pass flash-memory based strings to Serial.print() by wrapping them with F(). For example:

To send data without conversion to its representation as characters, use Serial.write().

Syntax

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.

Returns

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

Serial Print Values Online

Active12 months ago

I've this code:

and works fine. There's an example of the output:

but I wonder if there's a way to write the four sentences in one with something like:

that returns an error:

Any idea?. Thanks in advance.

Salvador Rueda
Salvador Rueda

Serial.print Multiple Values

Salvador Rueda
3031 gold badge4 silver badges12 bronze badges

2 Answers

Serial

String concatenation can be very useful when you need to display a combination of values and the descriptions of those values into one String to display via serial communication.

We can concatenate multiple values, forming a string with all the data and then send it.This can also be used with LCD dislpay.

Art Print Value

user3923880user3923880

There is a quicker way:Just convert your output directly to a String:

Serial Print Values
GuestGuest

Not the answer you're looking for? Browse other questions tagged arduino-ide or ask your own question.