Arduino Nano ESP32 - Serial Monitor

This tutorial provides instructions on how to use Serial Monitor on Arduino IDE with Arduino Nano ESP32

Hardware Preparation

1×Arduino Nano ESP32
1×USB Cable Type-C
1×(Optional) DC Power Jack
1×Breadboard
1×Jumper Wires
1×(Recommended) Screw Terminal Adapter for Arduino Nano

Or you can buy the following sensor kit:

1×DIYables Sensor Kit 30 types, 69 units
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. We appreciate your support.

Overview of Serial Monitor

When you program for ESP32, You need to have something to know how Arduino Nano ESP32 code run ⇒ use Serial Monitor tool in Arduino IDE. It is designed for two purposes:

  • Arduino Nano ESP32 → PC: Your code on Arduino Nano ESP32 send data via Serial. Yhe Serial Monitor on PC receives the data and display it. This is very useful for debugging and monitoring
  • PC → ESP32: You type some data and send it from PC to Arduino Nano ESP32. This is useful to send comamand from your PC to Arduino Nano ESP32

You need an micro USB cable between PC and Arduino Nano ESP32. This cable is also used to upload the code to Arduino Nano ESP32.

How To Use Serial Monitor

Open Serial Monitor

You just need to click on an icon on Arduino IDE as below image:

How to open serial monitor on Arduino IDE

Components on Serial Monitor

The Serial Momitor is composed of 8 components

  1. Output console: this component displays data received from Arduino Nano ESP32.
COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  1. Autoscroll checkbox: this component offers options to enable/disable the automatic scroll on the output console.
COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  1. Show timestamp checkbox: this component offers options to add timestamp before data.
COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  1. Clear output button: When this button is clicked, the text on the output console is cleared.
COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  1. Baud rate selection: this component offers options to select communication speed (baud rate) between PC and Arduino Nano ESP32. This value MUST be the same as the value used in Arduino Nano ESP32 code (in Serial.begin() function).
COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  1. Textbox: this component allow you to type characters that will be sent to Arduino Nano ESP32 board when you click Send button
COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  1. Ending selection: this component offers options to select the ending characters appended to data sent to Arduino Nano ESP32. Available options include:
    • No line ending: adds nothing
    • Newline: adds newline (LF, or '\n') character
    • Carriage return: adds carriage return (CR, or '\r') character
    • Both NL and CR: adds both newline and carriage return characters
    COM6
    Send
    Autoscroll Show timestamp
    Clear output
    9600 baud  
    Newline  
    1. Send button: when this button is clicked, The Serial Monitor sends data in Textbox plus the ending characters to Arduino Nano ESP32
    COM6
    Send
    Autoscroll Show timestamp
    Clear output
    9600 baud  
    Newline  

Arduino Nano ESP32 To PC

How to send data from Arduino Nano ESP32 board to PC:

  • Set the baud rate and initialize Serial port by using Serial.begin() function
Serial.begin(baudrate);
  • Send data to Serial Monitor using one of the below functions:
  • For example, send “Hello World!” to Serial Monitor

    Serial.println("Hello World!");

    Example Use

    The below example code sends the “esp32io.com” from Arduino Nano ESP32 to Serial Monitor every second

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

    Detailed Instructions

    • If this is the first time you use Arduino Nano ESP32, see how to setup environment for Arduino Nano ESP32 on Arduino IDE.
    • Copy the above code and paste it to Arduino IDE.
    • Compile and upload code to Arduino Nano ESP32 board by clicking Upload button on Arduino IDE
    • Open Serial Monitor on Arduino IDE
    • Select baurate 9600
    • See the output on Serial Monitor
    COM6
    Send
    esp32io.com esp32io.com esp32io.com esp32io.com
    Autoscroll Show timestamp
    Clear output
    9600 baud  
    Newline  
    • Try changing Serial.println() function to Serial.print() function

PC To Arduino Nano ESP32

How to send data from PC to Arduino Nano ESP32

  • On the PC:
    • Type text on Serial Monitor
    • Click Send button.

    And then you write Arduino Nano ESP32 code to read data and process it:

    • Set baud rate and begin Serial port
    Serial.begin(baudrate);
    • Check if the incoming data is available
    if(Serial.available()) { // TODO }
    • Read data from Serial port using one of the blow functions:
    • For example:

      String data = Serial.readStringUntil("\r\n");

      Example Use

      The below Arduino Nano ESP32 example code reads commands from Serial to turn on/off a built-in LED.

      • If the received text (command) is “ON”, turn the LED on
      • If the received text (command) is “OFF”: turn the LED off
      How Arduino Nano ESP32 can recognize a command? For example, when we send “OFF” characters, how Arduino Nano ESP32 can distinguish the command is “O”, “OF” or “OFF”?

      ⇒ We need to send a terminator along with a command ⇒ we can append a newline character ('\n'). To append newline character, select “newline” option on Serial Monitor before sending the data. Arduino Nano ESP32 will read data until the newline character. In this case, the newline character is called terminator or delimiter.

      /* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-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 newline character if (command == "ON") { digitalWrite(LED_BUILTIN, HIGH); // turn on LED Serial.println("Turn LED ON"); } else if (command == "OFF") { digitalWrite(LED_BUILTIN, LOW); // turn off LED Serial.println("Turn LED OFF"); } } }

      Detailed Instructions

      • If this is the first time you use Arduino Nano ESP32, see how to setup environment for Arduino Nano ESP32 on Arduino IDE.
      • Copy the above code and paste it to Arduino IDE.
      • Compile and upload code to Arduino Nano ESP32 board by clicking Upload button on Arduino IDE
      • Open Serial Monitor on Arduino IDE
      • Select baurate 9600 and newline option
      • Type “ON” or “OFF” and click Send button
      COM6
      Send
      Autoscroll Show timestamp
      Clear output
      9600 baud  
      Newline  
      • See the built-in LED's state on Arduino Nano ESP32 board. We will see LED's state is ON or OFF, respectively.
      • We also see LED's state on Serial Monitor
      COM6
      Send
      Turn LED ON
      Autoscroll Show timestamp
      Clear output
      9600 baud  
      Newline  
      • Type “ON” or “OFF” command several times.

Video Tutorial