ESP8266 - Serial Monitor

Hardware Preparation

1×ESP8266 NodeMCU
1×Micro USB Cable
1×(Optional) 5V Power Adapter for ESP8266
1×(Optional) ESP8266 Screw Terminal Adapter

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

Serial Monitor is a tool found in the Arduino IDE. It serves two functions:

  • ESP8266 to PC: Receiving data from the ESP8266 and displaying it on the screen. This is typically used for debugging and monitoring.
  • PC to Arduino: Sending commands from the PC to the ESP8266.

We MUST connect ESP8266 and PC via a USB cable in order to use Serial Monitor. This same cable is used to upload the code to ESP8266, and data is exchanged between Serial Monitor and ESP8266 through it.

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

*Output console: Show data that has been obtained from ESP8266.

COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

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

COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

*Provide a checkbox for displaying timestamps: an option to show the timestamp before the data that appears on the Serial Monitor.

COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  1. Button to Clear Output: Erase all text from the output console.
COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

*. 1. Choosing the baud rate: Select the communication speed (baud rate) between the ESP8266 and PC. 2. This value MUST match the one used in the ESP8266 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 is not altered, ESP8266 will be reset. Therefore, this is one method of resetting ESP8266.

*. Box for entering text:. A user can type characters that will be sent to an ESP8266.

COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  1. Ending selection:
    • Choose the characters to be appended to data sent to Arduino:
    • No line ending: no characters added
    • Newline: add newline (LF, or '\n') character
    • Carriage return: add 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 will cause the Serial Monitor to transmit the data in the textbox, along with the terminating characters, to the ESP8266.
    COM6
    Send
    Autoscroll Show timestamp
    Clear output
    9600 baud  
    Newline  

ESP8266 To PC

Set the baud rate and start the Serial port with the Serial.begin() function to transmit data from ESP8266 to PC.

Serial.begin(baudrate);
  • Using Serial.println("Hello World!").
  • Send data to Serial Monitor using one of the following functions: Serial.print(), Serial.println(), Serial.write().
  • For example, you can send “Hello World!” to Serial Monitor by using Serial.println("Hello World!").
Serial.println("Hello World!");

Example Use

In this instance, we will be transmitting “ArduinoGetStarted.com” from ESP8266 to the Serial Monitor once per second.

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

Detailed Instructions

To get started with ESP8266 on Arduino IDE, follow these steps:

  • Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
  • Wire the components as shown in the diagram.
  • Connect the ESP8266 board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
  • Copy the code and open it with the Arduino IDE.
  • Click the Upload button on the Arduino IDE to compile and upload the code to the ESP8266.
  • Launch the Serial Monitor.
  • Choose a baurate of 9600.
  • Check out the output on the Serial Monitor.
COM6
Send
ArduinoGetStarted.com ArduinoGetStarted.com ArduinoGetStarted.com ArduinoGetStarted.com
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • Consider substituting the Serial.println() function with Serial.print() function.

PC To ESP8266

How to send data from PC to Aduino and read it on ESP8266

Type text into the Serial Monitor and press the Send button.

Set the baud rate and start the Serial port by using the following ESP8266 code:

  • Read data from serial port

Retrieve data from the Serial port with the following ESP8266 code:

  • Process data

Process the data with the help of the following ESP8266 code:

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

Example Use

In this example, we will be sending commands from Serial Monitor to ESP8266 to activate or deactivate the in-built LED. The commands are as follows:

  • “ON”: to switch on the LED
  • “OFF”: to switch off the LED

How can ESP8266 recognize a full command? For example, when we send “OFF”, how can ESP8266 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. ESP8266 will read data until it encounters the newline character. This character is referred to as a delimiter.

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-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

  • Wire the components as shown in the diagram.
  • Connect the ESP8266 board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
  • Copy the code and open it in Arduino IDE.
  • Click the Upload button to upload the code to the ESP8266.
  • Open the Serial Monitor.
  • Set the baurate to 9600 and select the newline option.
  • Type “ON” or “OFF” and press the Send button.
COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • Check the built-in LED on the ESP8266 board. Its state will be either ON or OFF.
  • We can also view 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