Arduino Nano - Serial Monitor

Hardware Preparation

1×Arduino Nano
1×USB A to Mini-B USB cable
1×(Recommended) Screw Terminal Expansion Board for Arduino Nano
1×(Recommended) Breakout Expansion Board for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of Serial Monitor

Serial Monitor is one of the tools in Arduino IDE which is used for two distinct functions:

  • From Arduino Nano to PC: Data is received from Arduino Nano and displayed on the screen. This is usually done for debugging and monitoring.
  • From PC to Arduino: Commands are sent from PC to Arduino Nano.

To use Serial Monitor, we must connect Arduino Nano and PC via a USB cable. This same cable is also used to upload code to the Arduino Nano. Data is exchanged between Serial Monitor and Arduino Nano through this USB cable.

How To Use Serial Monitor

Open Serial Monitor

Click the Serial Monitor icon on the right side of Arduino IDE.

Arduino IDE - How to open serial monitor

Items on Serial Monitor

Print to the console: show information that has been received from the Arduino Nano.

COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Checkbox for Autoscroll: Option to choose between automatic scrolling and not scrolling.

COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

*Checkbox to enable display of timestamp before data shown on Serial Monitor.

COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

*ii. Clear Output Button: Erase all text from the output console.

COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

*. 1. Selection of baud rate: Choose the communication speed (baud rate) between Arduino Nano and PC. 2. This value must match the one used in the Arduino Nano code (in the Serial.begin() function).

COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

※ NOTE THAT:

When we choose a baud rate, even if the value remains unchanged, Arduino Nano is reset. Consequently, this is one method of resetting Arduino Nano.

*. Box for entering text:. A user can type characters into it to be sent to an Arduino Nano.

COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  1. Ending selection:
    • Choose the characters to be added to the data sent to Arduino:
    • No line ending: no additional characters
    • Newline: add a newline (LF, or '\n') character
    • Carriage return: add a carriage return (CR, or '\r') character
    • Both NL and CR: add both newline and carriage return (CRLF, or '\r\n') characters
    COM6
    Send
    Autoscroll Show timestamp
    Clear output
    9600 baud  
    Newline  

    *. 1. Pressing the Send button:. 2. This will cause the Serial Monitor to transmit the data in the textbox, along with the terminating characters, to the Arduino Nano.

    COM6
    Send
    Autoscroll Show timestamp
    Clear output
    9600 baud  
    Newline  

Arduino Nano To PC

Set the baud rate and initiate the Serial port using the Serial.begin() function to transmit data from Arduino Nano to PC.

Serial.begin(baudrate);
  • Using Serial.println():
  • Send data to the Serial Monitor utilizing one of these functions: Serial.print(), Serial.println(), Serial.write().
  • For instance, to send “Hello World!” to the Serial Monitor, use Serial.println():
Serial.println("Hello World!");

Example Use

In this example, we will transmit “ArduinoGetStarted.com” from Arduino Nano to the Serial Monitor at an interval of one second.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-serial-monitor */ void setup() { Serial.begin(9600); } void loop() { Serial.println("ArduinoGetStarted.com"); delay(1000); }

Detailed Instructions

  • Copy the code and open it with the Arduino IDE.
  • Click the Upload button in the Arduino IDE to send the code to the Arduino Nano.
  • Open the Serial Monitor.
  • Set the baurate to 9600.
  • Check the output on the Serial Monitor.
COM6
Send
ArduinoGetStarted.com ArduinoGetStarted.com ArduinoGetStarted.com ArduinoGetStarted.com
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • Attempt to substitute the Serial.println() function with Serial.print() function.

PC To Arduino Nano

How to send data from PC to Aduino and read it on Arduino Nano

Type your text in the Serial Monitor and then press the Send button.

Set the baud rate and initiate the Serial port by using the following Arduino Nano code:

  • Read data from Serial port

Retrieve data from the Serial port by using the following Arduino Nano code:

  • Process data

Process the data with the help of the following Arduino Nano code:

Serial.begin(baudrate);
  • Determine if data is present or not.
if(Serial.available()) { // TODO }
String data = Serial.readStringUntil("\r\n");

Example Use

In this example, we will be sending commands from Serial Monitor to Arduino Nano. The commands are as follows:

  • “ON”: the LED will be switched on
  • “OFF”: the LED will be switched off

These commands will be used to control a built-in LED.

How can Arduino Nano recognize a full command? For example, when we send “OFF”, how can Arduino Nano differentiate between “O”, “OF”, and “OFF”?

When sending a command, we will append a newline character ('\n') by selecting the “newline” option on the Serial Monitor. Arduino Nano will read data until it encounters the newline character. In this case, the newline character is referred to as a delimiter.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-serial-monitor */ void setup() { Serial.begin(9600); pinMode(LED_BUILTIN, OUTPUT); // set the digital pin as output: } void loop() { if(Serial.available()) // if there is data comming { String command = Serial.readStringUntil('\n'); // read string until meet newline character if(command == "ON") { digitalWrite(LED_BUILTIN, HIGH); // turn on LED Serial.println("LED is turned ON"); // send action to Serial Monitor } else if(command == "OFF") { digitalWrite(LED_BUILTIN, LOW); // turn off LED Serial.println("LED is turned OFF"); // send action to Serial Monitor } } }

Detailed Instructions

  • Copy the code and open it with Arduino IDE.
  • Click the Upload button on Arduino IDE to upload the code to Arduino Nano.
  • Open the Serial Monitor.
  • Choose a baurate of 9600 and select the newline option.
  • Type “ON” or “OFF” and then press the Send button.
COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • Check the built-in LED on the Arduino Nano board. It will be either ON or OFF.
  • Additionally, we can observe the LED's state on the Serial Monitor.
COM6
Send
LED is turned ON
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • Type the commands “ON” or “OFF” a few times.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!