Using the Serial Monitor

Understanding serial communication and using the Arduino IDE Serial Monitor for debugging

When you plug your ESP32 into your computer with a USB cable, you are not just powering the board — you are opening a two-way communication channel. This channel is how the Arduino IDE uploads your code, and how you can send and receive text messages between your computer and the ESP32. Understanding serial communication is one of the most useful debugging skills you can build.

🔗How the ESP32 Talks to Your Computer

The ESP32 itself does not speak USB natively (at least not the classic ESP32-WROOM-32). Instead, your dev board includes a USB-to-UART bridge chip that translates between USB (what your computer understands) and UART serial (what the ESP32 understands).

The two most common bridge chips are:

Bridge ChipCommon OnDriver Usually Needed?
CP2102 / CP2104Espressif DevKitC, many branded boardsUsually auto-detected on Windows 10+, macOS, Linux
CH340 / CH9102Budget boards, NodeMCU-32S clonesOften needs manual driver install, especially on macOS

When everything is working, your computer sees the ESP32 as a virtual serial port — something like COM3 on Windows, /dev/ttyUSB0 on Linux, or /dev/cu.usbserial-0001 on macOS.

Tip: If your board does not show up in the Arduino IDE port list, you almost certainly have a driver issue. Search for "CH340 driver" or "CP2102 driver" for your operating system.

🔗Installing CH340 Drivers

If your board uses a CH340 chip and is not recognized:

  • Windows: Download the CH340 driver from the manufacturer (WCH) and run the installer.
  • macOS: Install via Homebrew with brew install --cask wch-ch34x-usb-serial-driver, or download from WCH directly. On newer macOS versions you may need to allow the driver in System Settings > Privacy & Security.
  • Linux: Most modern kernels (4.x+) include CH340 support out of the box. If not, the ch341 module can be loaded with sudo modprobe ch341.

🔗A Note on Newer Boards

Some newer ESP32 variants — specifically the ESP32-S2 and ESP32-S3 — have native USB support built into the chip itself. These boards may not need a bridge chip at all. If you are using one of these, the serial port may appear as a USB CDC device rather than a traditional serial port. The concepts in this article still apply, but the port name and driver situation will differ.

For this guide, we assume you are using the recommended ESP32-WROOM-32 DevKit with a CP2102 or CH340 bridge chip.

🔗What Is Serial Communication?

Serial communication sends data one bit at a time over a wire. Your ESP32 and computer agree on a baud rate — the speed at which bits are sent — so that both sides can interpret the data correctly.

The most common baud rate for ESP32 work is 115200 bps (bits per second). This means roughly $115200 / 10 \approx 11{,}520$ characters per second (each character takes about 10 bits including start, stop, and framing bits).

Other common baud rates include 9600, 19200, 57600, and 921600. The key rule is simple: both sides must use the same baud rate, or you will see garbled text.

🔗Setting Up Serial in Your Sketch

To use serial communication in your Arduino sketch, you need two things: initialize the serial port in setup(), and then use print functions wherever you need output.

void setup() {
  Serial.begin(115200);  // Start serial at 115200 baud
  delay(1000);           // Give the serial port a moment to initialize

  Serial.println("ESP32 is ready!");
}

void loop() {
  Serial.println("Hello from the loop!");
  delay(2000);
}

🔗Key Serial Functions

FunctionWhat It DoesExample Output
Serial.print("text")Prints text, cursor stays on the same lineHello
Serial.println("text")Prints text followed by a newlineHello\n
Serial.print(42)Prints a number as text42
Serial.print(3.14, 2)Prints a float with 2 decimal places3.14
Serial.printf("Temp: %.1f C", t)Formatted output (like C printf)Temp: 23.5 C

Note: Serial.printf() is available on ESP32 but is not part of standard Arduino. If you are writing code that needs to be portable to other Arduino boards, stick with Serial.print() and Serial.println().

🔗The delay() After Serial.begin()

You will often see a short delay(1000) after Serial.begin(). This is because when the ESP32 resets, it takes a moment for the USB serial connection to be re-established on the computer side. Without the delay, your first few messages may be lost. This is especially common on boards with a CH340 bridge chip.

🔗Using the Arduino Serial Monitor

The Serial Monitor is a built-in tool in the Arduino IDE that lets you see what your ESP32 is printing and send text back to it.

🔗Opening the Serial Monitor

  1. Make sure your ESP32 is connected via USB.
  2. In the Arduino IDE, go to Tools > Serial Monitor (or press Ctrl+Shift+M / Cmd+Shift+M).
  3. Set the baud rate in the bottom-right dropdown to 115200 (or whatever you used in Serial.begin()).

You should see text appearing as your ESP32 prints it.

Warning: If you see garbled characters like ⸮⸮⸮⸮⸮ or random symbols, the baud rate does not match. Check that the Serial Monitor baud rate matches the value in your Serial.begin() call.

🔗Sending Data to the ESP32

The Serial Monitor also lets you send text to the ESP32. Type in the text field at the top and press Enter (or click Send). Your sketch can read this input:

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("Type something and press Enter:");
}

void loop() {
  if (Serial.available() > 0) {
    String input = Serial.readStringUntil('\n');
    input.trim();  // Remove any trailing whitespace or carriage return

    Serial.print("You typed: ");
    Serial.println(input);
  }
}

Serial.available() returns the number of bytes waiting to be read. Serial.readStringUntil('\n') reads characters until it hits a newline (which is sent when you press Enter).

Tip: In the Serial Monitor, make sure the line-ending dropdown (next to the baud rate) is set to "Newline" or "Both NL & CR". If it is set to "No line ending," readStringUntil('\n') will wait indefinitely.

🔗The Serial Plotter

The Arduino IDE also includes a Serial Plotter (Tools > Serial Plotter), which graphs numerical values over time. This is extremely useful for visualizing sensor data.

To use the Serial Plotter, simply print numbers — one per line for a single value, or multiple values separated by commas or tabs for multiple lines on the same graph:

void setup() {
  Serial.begin(115200);
}

void loop() {
  int sensorValue = analogRead(34);  // Read from GPIO 34 (input-only pin)
  float voltage = sensorValue * (3.3 / 4095.0);

  // Print both values — the plotter will show two lines
  Serial.print(sensorValue);
  Serial.print(",");
  Serial.println(voltage);

  delay(50);  // ~20 readings per second
}

The Serial Plotter will display two lines: one for the raw ADC value and one for the calculated voltage. This is a great way to see how a sensor responds to changes in real time.

Tip: The Serial Plotter and Serial Monitor cannot be open at the same time. Close one before opening the other.

🔗Practical Debugging Patterns

Serial output is the simplest debugging tool you have. Here are patterns you will use constantly:

int temperature = 24;
float humidity = 61.5;

Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");

Serial.printf("Humidity: %.1f%%\n", humidity);

🔗Mark Where Your Code Reaches

void setup() {
  Serial.begin(115200);
  delay(1000);

  Serial.println("Starting setup...");

  // ... some initialization code ...
  Serial.println("WiFi initialized.");

  // ... more code ...
  Serial.println("Sensor initialized.");

  Serial.println("Setup complete!");
}

If your board crashes or hangs, the last message you see tells you where the problem is.

void loop() {
  unsigned long start = millis();

  // ... do some work ...

  unsigned long elapsed = millis() - start;
  Serial.printf("Loop took %lu ms\n", elapsed);
}

🔗Common Serial Issues and Fixes

ProblemLikely CauseFix
No port appears in IDEMissing driver, bad cableInstall CP2102/CH340 driver; try a different USB cable (some are charge-only)
Garbled outputBaud rate mismatchMatch the Serial Monitor baud rate to Serial.begin()
Messages appear but are cut offMissing delay() after beginAdd delay(1000) after Serial.begin()
Random reboot messages on connectESP32 boot log at 115200Normal — the ESP32 prints boot info on every reset
Port disappears during uploadDriver or power issueTry a different USB port; avoid USB hubs

Tip: If you are hunting for a USB cable that supports data (not just charging), look for one labeled "data cable" or "sync cable." A quick test: if your phone shows up as a storage device when connected with the cable, it carries data.

🔗What's Next?

Now that you can send and receive data between your ESP32 and your computer, you have the most important debugging tool in your toolkit. In the next article, we will look at how to power your ESP32 for standalone projects where it is not tethered to your computer by USB.