Writing To Console with Arduino | SOLVED

How the heck do you write and print text to the Arduino console, you know, that black output section at the bottom of the Arduino IDE? Is it even possible?!  Have you been reading about Serial.print(), but it just isn’t making any sense at all?

You just want to be able to view the state of some variables, I mean what gives! This should be easy!

Lesson Outline:

In this lesson…

  • You will learn exactly how to print and write text to the Arduino console

Spoiler Alert – you may have been looking for love in all the wrong places – it’s not actually the console! You’ll write to the Serial Monitor.

  • You will learn the two REQUIRED functions to write text on the Arduino console Serial Monitor
  • As a bonus, you’ll also learn how to avoid two of the most common printing gotchas that always trip people up when they are getting started with Arduino.

Arduino Console Serial Monitor

When you open up the Arduino IDE, and you see the black section at the bottom that takes up 20% of the window, you might have assumed (very appropriately) that this was a console where you can print out text and values.

Similar to what you’ll find in other IDEs like Visual Studio, Eclipse, or whatever you’re familiar with. Trust me – just about everybody new to Arduino IDE thinks the exact same thing – so you are not alone!

But in fact, this IS NOT one of the functions of the Arduino console. Its only purpose is to display error messages and status information about your Arduino.

If you want to see text output like you think of on a console, you need to use the Serial Monitor Window. The Serial Monitor window can be found under Tools > Serial Monitor.

Arduino tools menu showing Serial Monitor shortcut for printing to console

Programming Electronics Academy members, check out the Arduino Course for Absolute Beginners to practice using the Serial Library in your code.

Not a member yet?  Sign up here.

Arduino Serial Monitor Gotchas

But there are a couple gotchas that might really trip you up when writing text the console Serial Monitor.

Gotcha 1: Baud rate does not match

Sometimes you see what looks like Egyptian hieroglyphics printed on the Arduino Console Serial Monitor.  This happens when the number you put into the Serial.begin() function does not match the baud rate set in the serial monitor window drop down.

arrow showing Baud rate in Serial.print and baud rate in Serial monitor window, must match to print to console correctly

If these two baud rates don’t match, you get a bunch of garbled stuff printed to the Arduino console Serial Monitor window. A common baud rate is 9600, as is 115200. For most applications it doesn’t matter that much, as long as the value matches in the code and the Serial Monitor window setting.

Gotcha 2: Values keep printing horizontally on the Arduino Console Serial Monitor

You may have noticed, when you use the Serial.print() function, that the values get displayed over and over horizontally across the Arduino Console Serial Monitor. To change this, just use the Serial.println() function instead of Serial.print().

The Serial.println() function creates a new line after everything it prints. So now your values will be displayed vertically down the Arduino Serial Monitor.

Jump Start your Arduino Training

I hope you found this lesson helpful! We have just touched the tip of the iceberg here with how the Serial Monitor works – there is a ton more and if you’d like to fast track your Arduino coding and prototyping skills I highly recommend checking out the Programming Electronics Academy training program.

Programming Electronics Academy offers multiple in-depth, concise courses in our membership program. From a deep dive into programming Arduino, to creating Internet of Things connected devices.

You will learn a strategy for creating your prototypes and actually getting something working – that is, you’ll gain the confidence to actually apply what you learn.

Arduino Code Example

This code was submitted by one of our members to demonstrate basic serial communication.

Upload this code to your Arduino board, and open up the serial monitor window.  What do you expect to see?

//A simple program to demonstrate serial communications.

//Pretend data to start off with.
int sensorData = 0;

//This will only run once.
void setup() {
  Serial.begin(9600);
}

//This will run over and over.
void loop() {

  //Send data to the Serial Port
  Serial.print("Sensor Data = ");
  Serial.println(sensorData);

  //Increment the sensor value
  sensorData = sensorData + 1;

  delay(30);
}
AppLab Bricks open in background with actual brick

Arduino AppLab Bricks → Marketing Garbage or New Powerful Interface?

Arduino Ventuno single board computer - top side

New Ventuno Q Dual Brain Single Board Computer

AppLab Pip Install

How to Add Python Packages in Arduino AppLab (No pip install needed)

Arduino Power Section Schematic

Kit-on-a-Shield Schematic Review

Just how random is the ESP32 random number generator?

Just how random is the ESP32 random number generator?

14 Comments

  1. Barry Thomas on March 26, 2021 at 3:39 pm

    Could be an idea to get started with sprintf or printf

  2. Gordon Reed on March 27, 2021 at 10:30 am

    Need a good article on Serial I/O.

  3. Gio on March 27, 2021 at 2:21 pm

    Thank you for tip. Will try it.
    Note: it’s CONSOLE not Council.
    Cheers

    • Michael James on March 27, 2021 at 2:40 pm

      Thanks for the note Gio! I’ve gotten that feedback quite bit from this lesson, and I am practicing my pronunciation of Console.
      Sometimes I think I am tone deaf – I also have trouble pronouncing attribute. But hey, knowing is half the battle!

  4. Anthony Lopez on March 27, 2021 at 3:47 pm

    Any space for a comment?
    great if it fits,
    sometimes we need to go over stuff we commonly use and this is a great reminder for us all. 🙂
    thanks

  5. Reid Richard on March 31, 2021 at 3:28 am

    //A program to demonstrate serial communications.

    //Pretend data to start off with.
    // int variables are limited to -32767 to psitive 32,767 then they rollover.
    int sensorData = 1000/32750;
    // replace the 1000 above with 32,750 to watch the rollover happen quickly.
    //This will only run once.
    void setup() {

    //Set the baud rate in bits per second.
    Serial.begin(9600);

    }

    void loop() {

    //Send data to the Serial Port
    Serial.print(“Uno Sensor Data = “);
    Serial.println(sensorData);

    //Increment the sensor value
    sensorData = sensorData + 1;

    //I have choosen to increment “sensorData” by 1. you can make this any value that you want it to be.

    // you can play with the delay value, make it longer or shorter to make the sketch run faster or slower.

    delay(30);

    //upload the code to your uno…. then open the serial monnitor and watch the numbers add up higher and higher and see what they do when they rollover. Enjoy.

    }

  6. Donna Cann on January 1, 2022 at 11:58 am

    Put in this exact code from above,, but keep getting error msg that “sensordata” was not declared in this scope..am newbie and any suggestions…

    • Michael James on January 2, 2022 at 5:00 pm

      Great question Donna! My guess is you need to capitalize the letter d in sensorData to match the variable declaration.

  7. rich engle on January 13, 2022 at 12:04 am

    thank u so much. i used the serial plotter too, and can see the graphs! thx again

Leave a Comment