You don't need anything connected to your Arduino for this sketch. The Arduino DOES need to be connected to your computer but nothing else (thanks Jacob!). It just runs through some of the structures that are needed to open and use the serial monitor with the IDE.

Step 1:

In the top right corner of the your sketch window is the 'button' for opening the serial monitor. You can also find it in the Tools drop down menu.

When you open your serial monitor you will get a window that looks something like this.

Step 2: Upload the Code (and Save As!):

Here's the code for exploring the serial monitor. Upload it and open the serial monitor. You only need the Arduino connected to your computer. Look at how the print statements in the sketch are written and what shows on the serial monitor. Notice the difference between Serial.print() and Serial.println(). The 'Serial.' begining to the command identifies that this is an predefined command that is used for serial communication. When the monitor asks for an input you type it into the input bar at the top of the monitor window and hit return. Explore what happens when you forget to hit return, what happens if you give it nothing, what happens if you give it a letter instead of a number, what happens if you give it a number before it asks for one. Explore and notice!! Also notice that the last number is either 'last' if it's an integer or 'numbr' if it's a decimal (float) value. You can comment out the integer lines and uncomment the float lines (2 lines in each case) to see the difference.

/*
   SerialMonitorTest (public domain)

   This is a quick sketch to open the serial monitor and write information to 
   the monitor. Also some quick tools to enter numbers into the monitor.

   This statement in the setup() loop initializes the serial monitor.
   Serial.begin(9600); //Setting baudrate at 9600

   It takes a couple of moments to get the serial monitor communicating (like a phone call)
   so this next statement makes everything wait until the monitor is connected.
    while (!Serial) {
      ; // wait for serial port to connect. Needed for native USB
     }
   7/6/20
   Bruce Emerson
*/

int last = 6;
float numbr = 6.;
 
    void setup() {
     Serial.begin(9600); //Setting baudrate at 9600
     while (!Serial) {
      ; // wait for serial port to connect. Needed for native USB
     }
     Serial.println();
     Serial.println("The Serial Monitor is ready for business!");
     Serial.println();
     delay(2000);
     }
     
    void loop() {
     Serial.println("The following is an example of Serial.print()");
     Serial.print("1,  ");
     delay(300);
     Serial.print("2,  ");
     delay(300);
     Serial.print("3,  ");
     delay(300);
     Serial.print("4,  ");
     delay(300);
     Serial.print("5,  ");
     delay(300);
     Serial.println(last);
//     Serial.println(numbr);
     delay(5000);

     // This section requests a new final digit for the series above
     Serial.println("New last digit? ");
     delay(5000);
     
     //This checks to see if the user has entered something on the top line of
     // the serial monitor and hit return. Explore what happens if you don't hit
     // return or don't enter a number for more than 5 s
     if (Serial.available()){    
       last = Serial.parseInt(); // the input can be parsed into a floating pt also
 //      numbr = Serial.parseFloat(); // the input can be parsed into a floating pt also
       }
     }
        

Step 3: Learn

Some things to notice about this sketch and how it relates to what you see on the Serial Monitor. As you have seen previously actions on the Arduino often need to some preparation to get things started.

Serial.xxx: The commands that control and communicate with the serial monitor on your computer are built into the basic operation of the Arduino. Functions which talk to the serial monitor all start with Serial.xxx. This is a reserved name so if you try to use SerialNumber to label a variable the Arduino will be unhappy and potentially confused. You can tell that the IDE recognizes Serial.xxx as a special command because it immediately changes color as you enter it. This is a way of telling you that this is a reserved label.

Serial.begin(): This function initiates the communication between the Arduino and the serial monitor window on your computer. This is sometimes called 'initializing the serial monitor'. One of the things the serial monitor needs to know is how fast are you planning to send information. This is called the baud rate and is expressed in bits/second. 1 baud is 1 bit/s. It is typical to use 9600 baud for commuication with the Arduino Uno. Other baud rates are possible but my knowledge is not extensive enough to understand the limitations and choices.

Wait for Serial to Connect: The following bit of code is a clever way of checking in with the serial monitor to be sure it has gotten started. What this bit of code says in English is 'While the serial monitor is NOT ready (!Serial => not ready) the do nothing (; - this is an active line of code with nothing to do) and the check again to see if the serial monitor is ready'. I think of this as very much like the kid in the back seat who keeps asking 'Are we there yet?' until the answer is yes and then they relax.

while (!Serial) {
      ; // wait for serial port to connect. Needed for native USB
	  }

Serial.print() or Serial.println(): These functions allow us to communicate with the user by writing (print) characters and numbers to the serial monitor window on our computer. Look at the linked reference pages to see more examples.

Serial.available(): You will notice that there is a space at the top of the serial monitor window which is where we can enter information that the Arduino can read from the serial monitor.

When you type something into this entry space the serial monitor notices that something is available. The Serial.available() function notices and responds telling the Arduino how much information is available. We can now 'read' that data using another Serial.xxx command.

Serial.parseInt() and Serial.parseFloat(): There are a number of ways to 'read' information from the serial window. Not surprisingly Serial.read() is one of them. In this case I am using a more explicit read function that looks for specific types of information. In the first case it is looking for an integer and in the second case it is looking for a floating point number. You might experiment with what happens if you give it a character like 'a'.

Step 4: Done!

Questions? Here is the manual page for the Serial Monitor from the folks at Arduino. Lots of things I haven't explored at the bottom.