Course Content
IoT Engineering Course using ESP32 with 12 Real-World Projects

📘 Serial Monitor Basics

(Deep Technical Explanation)


🎯 Lesson Objective

By the end of this lesson, students will:

  • Understand what Serial Communication is

  • Understand how ESP32 communicates with a computer

  • Learn about baud rate

  • Use Serial Monitor for debugging

  • Understand Serial.begin(), Serial.print(), and Serial.println()

  • Debug real sensor data


1️⃣ What is Serial Communication?

Serial communication is a method of sending data one bit at a time over a communication channel.

In simple words:

It is how ESP32 talks to your computer.

When you print something using Serial Monitor, you are sending data from ESP32 to your PC through USB.


2️⃣ Why Serial Monitor is Important

Serial Monitor is used for:

  • Debugging code

  • Printing sensor values

  • Checking logic

  • Finding errors

  • Monitoring system behavior

Without Serial Monitor, you are coding blindly.

In real engineering:

Serial debugging is mandatory.


3️⃣ How Serial Communication Works in ESP32

When you connect ESP32 using USB:

USB Cable → USB to Serial Converter → ESP32 UART

ESP32 uses UART (Universal Asynchronous Receiver Transmitter).

Data flow:

ESP32 → USB chip → Computer → Serial Monitor window


4️⃣ What is Baud Rate?

Baud rate = Speed of communication.

It represents how many bits are sent per second.

Common baud rates:

  • 9600

  • 115200 (recommended for ESP32)

Example:

 
Serial.begin(115200);
 

This means:

ESP32 communicates at 115200 bits per second.

Important Rule:

Baud rate in code must match baud rate in Serial Monitor.

If not:

You will see garbage characters.


5️⃣ Basic Serial Functions


🔹 Serial.begin()

Initializes serial communication.

Example:

 
Serial.begin(115200);
 

Must be inside setup().


🔹 Serial.print()

Prints data without moving to next line.

Example:

 
Serial.print(“Temperature: “);
 

🔹 Serial.println()

Prints data and moves to next line.

Example:

 
Serial.println(“25”);
 

Difference:

Function Behavior
print() Same line
println() New line

6️⃣ First Serial Example

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

void loop() {
Serial.println(“Hello ESP32”);
delay(1000);
}

 

Output:

Hello ESP32
Hello ESP32
Hello ESP32


7️⃣ Printing Variables

Serial Monitor is used to print variable values.

Example:

 
int temperature = 28;

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

void loop() {
Serial.print(“Temperature: “);
Serial.println(temperature);
delay(2000);
}

 

Output:

Temperature: 28


8️⃣ Debugging Logic Using Serial

Example:

 
int temp = 32;

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

void loop() {
if (temp > 30) {
Serial.println(“AC ON”);
} else {
Serial.println(“AC OFF”);
}
delay(2000);
}

 

Serial helps you confirm:

Is condition working?
Is logic correct?

Without Serial, you don’t know.


9️⃣ Reading Sensor Values Using Serial

Example with analog input:

 
int gasValue;

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

void loop() {
gasValue = analogRead(34);

Serial.print(“Gas Value: “);
Serial.println(gasValue);

delay(1000);
}

 

Output:

Gas Value: 532
Gas Value: 540

Now you can decide threshold.

This is how calibration works.


🔟 Serial Monitor Settings

In Arduino IDE:

Tools → Serial Monitor

Important settings:

✔ Baud rate must match
✔ Line ending (No line ending / Newline)
✔ Autoscroll


1️⃣1️⃣ Sending Data from Serial Monitor to ESP32

Serial communication is two-way.

Example:

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

void loop() {
if (Serial.available()) {
char input = Serial.read();
Serial.print(“You typed: “);
Serial.println(input);
}
}

 

Now if you type “A” in Serial Monitor:

Output:

You typed: A

This allows manual control.


1️⃣2️⃣ Serial for Professional Debugging

In large projects:

Engineers print:

  • Sensor values

  • State changes

  • Mode changes

  • WiFi connection status

  • Error messages

Example:

 
Serial.println(“Connecting to WiFi…”);
Serial.println(“WiFi Connected!”);
Serial.println(“Gas Detected!”);
 

This makes debugging easy.


1️⃣3️⃣ Common Mistakes

❌ Forgetting Serial.begin()
❌ Baud rate mismatch
❌ Not opening Serial Monitor
❌ Using wrong COM port
❌ Printing too fast without delay


1️⃣4️⃣ Best Practices

✔ Always start debugging with Serial
✔ Print labels with values
✔ Keep clear formatting
✔ Use delay during debugging
✔ Remove unnecessary prints in final code


📌 Lesson Summary

In this lesson, we learned:

  • What is serial communication

  • How ESP32 communicates with computer

  • What is baud rate

  • Serial.begin()

  • Serial.print() vs println()

  • Debugging sensor values

  • Two-way serial communication

  • Common errors

Serial Monitor is your debugging window.

Master it, and you can build any IoT system.

Scroll to Top