SW1: Serial Monitor

The Serial Monitor is a very useful tool once the code to write moves a bit from the very basics.

We can use the Serial Monitor to print anything we want: variables’ value, values coming from a sensor, a custom debugging string and so on.

In order to open the Serial Monitor we have to connect Arduino to the PC and then to click on the magnifier icon on the right side of the Arduino IDE.

Let’s see how it looks

serial monitor

On top we have an input field where we can write anything and that will be sent to Arduino. The big area is where we will print the data.

At the bottom right there are 2 dropdown menu. The first one sets the new line character, it is not so interesting. The second menu lets us decide the baud rate to communicate to the Serial Monitor. As we will see in few moments we have to declare the baud rate at which we will send data to the Serial Monitor. The baud rate set in the code must match the one set in the Serial Monitor. The default is 9600 and if you haven’t a special reason to use a different one, you can use that value.

A first example to show how we can interact with Arduino from our keyboard. 

Load this code to Arduino, open the Serial Monitor and into the input field write 0 or 1, then hit Send.

If you send a 1, Arduino will light the L LED, if you send a 0 the LED will turn off. In addition you will read some output in the Serial Monitor. The output is generated by Serial.print() and Serial.println() . The difference between the two functions is that the first writes an output and keeps the curson on the same line, the second adds a new line after the printed string.

Of course you can have a much more complex interaction with Arduino, you are not limited to turn on and off an LED.

How to read incoming data from a component.

Connect a potentiometer as shown below

serial monitor and potentiometer

Now copy this code into Arduino IDE

Load the code to Arduino, open the Serial Monitor and rotate the potentiometer shaft back and forth.

Each second Arduino will read the output value from the middle pin of the potentiometer and will write it to the Serial Monitor. In addition, just to show that we can do something with those data, each time we check if Arduino receives a value higher than 511. If the received value is higher we turn on the LED, if not we turn it off.

Now that we know how to read incoming data and to print them along with custom strings to the Serial Monitor it will be easy to use this tool for debugging purposes.


I’ve tested the circuit and the code posted in this article on my equipment and they work properly, anyway I do not assume any responsibility for any damage which your components could suffer.