The Serial Monitor

Step 1
Serial communication is where data is sent one bit at a time between two devices.

The Arduino and computer communicate via Serial through the USB cable.


In this lesson we will learn to use the Serial Monitor to display this data to our computer.

Step 2
Click on this icon to open the Serial Monitor

We haven't printed any data to it yet so it's blank right now.

Step 3
First use Serial.begin() to initialize serial communication

We do this once in the setup() function.


We need to specify a rate at which data is transferred, and 9600 is the default rate for the serial monitor so we use that.

Step 4
Now we can print data to the serial monitor

We can do this with Serial.print()and Serial.println(). (That's println with an L).

Both functions do the same thing, but println() (print line) creates a new line after sending, so we will use that one.

Check Your Work
Step 5
Upload your code and watch it through the Serial Monitor
Temp1491865216 Temp1491865192

You should see this:

Step 6
We can remove these lines now, they will only get in the way
Step 7
We're going to now create a variable and use the Serial monitor to watch it change

Unlike in JavaScript where we would define any variable using var, in C++ we must also declare what type of data the variable holds.


Here are some example data types:

int: a number without a decimal place.
float: a number with decimal places.
char: a character such as 'a'.
Servo: a Servo is a data type too.
Step 8
We first declare our variables at the top of our program

We must first declare our variables even exist before we can start using them.


Declaring a variable outside of a function puts it in the global scope. Meaning any function can use it.

Step 9
We use the setup() function to initialize our variables

We need to give our variable a value to start at.

Step 10
In the loop() function, increment the value of myNumber by 1

We use the symbol += to increment a variable by an amount


Remember that += is short-hand. We could have said

myNumber = myNumber + 1;

//equivalent to
myNumber += 1;
Step 11
Now we want to print this value to the Serial Monitor

Since we want it to show us the number every time it updates, we will put our println() inside the loop function.


Also we will put in a delay, just so it doesn't update too fast.

Check Your Work
Step 12
Upload your code and open the Serial Monitor.

You should see the value of the variable myNumber as it increases by 1 every 100ms.

Step 13
Let's use the Serial monitor to read the position of a dial

We can use the Serial Monitor to view information we don't already know such as the position of this potentiometer


We can use the position of the dial as INPUT for our CONTROLLER

Step 14
Use this schematic to set up your potentiometer

Use your breadboard to help you set this up.

Use analog pin 0. Just so we're all on the same page.


HINT: These here are your analog pins!

Step 15
Set the value of myNumber to the value being INPUT in to pin A0

We will use the function analogRead() which will return a number between 0-1023 based on the amount of current going in to the pin


Also, remove the increment on myNumber.

Check Your Work
Step 16
Now upload your code and read the value of the potentiometer

We now have INPUT data! In the next lesson we will use this to CONTROL our OUTPUTS.

The value of myNumber as I turn the knob:

Step 17
Use this INPUT to CONTROL the speed of a servo

Hook up a servo, and use writeMicroseconds() to set its speed.

You'll need to modify your INPUT data a little.

  • Your data will range from 0-1000
  • The servo needs values from 1000-2000

How much do you need to add to your input data so that you can use it to control your servo?

Check Your Work
Step 18
You should now be able to change the speed of your servo by twisting the potentiometer
Step 19
Many different components can be used as input

For example a distance sensor or a temperature sensor can supply INPUT to our Arduino.

with INPUT our CONTROLLER can make decisions and produce them as OUTPUT.


We will explore some of these components in future lessons.

The Serial Monitor Info


MVCode Clubs

Created By

Newprofile jamie


Introduction to Robotics: Remote Control Car

Access Level


For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.

Learn more about MVCode Teach