Arduino programming guide series

Focus on the type parameter in "println()"

We use the println() function to print a string to the serial monitor. The same function is overloaded with a second parameter that allows us to designate the type of data we want to display.

"Serial.println()" is one of the most useful functions in the Arduino language. It will print a string or a number to the serial monitor. It is an easy way to get data out of a sketch.

The most common way to use "println()" is like this:

Serial.println("This will print this message to the Serial monitor");

In this example, the single parameter of the function contains a String.

But, did you know that this function is overloaded, and can accept a second parameter? 

The second parameter gives you the opportunity to specify the type of the data you specify in the first parameter.

Here's two examples:

  • Serial.println(21, DEC) will print "21" in the serial monitor.
  • Serial.println(21, BIN) will print "00010101 " in the serial monitor.

The "println()" function accepts the following types:

  • DEC for decimals
  • HEX for hexadecimals
  • OCT for octals
  • BIN for binary numbers

The type parameter is optional, so you can choose to not include one in your println instruction. In that case the output will default to decimal (DEC).

More details about this parameter are available in the documentation.

New to the Arduino?

Arduino Step by Step Getting Started is our most popular course for beginners.

This course is packed with high-quality video, mini-projects, and everything you need to learn Arduino from the ground up. We'll help you get started and at every step with top-notch instruction and our super-helpful course discussion space.

Last Updated 8 months ago.

We publish fresh content each week. Read how-to's on Arduino, ESP32, KiCad, Node-RED, drones and more. Listen to interviews. Learn about new tech with our comprehensive reviews. Get discount offers for our courses and books. Interact with our community. One email per week, no spam; unsubscribe at any time

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}