⚡ ESP32 – Complete In-Depth Guide

32-bit Microcontroller with Built-in WiFi & Bluetooth

ESP32 is NOT just a microcontroller — it is a complete IoT System on Chip (SoC) with dual-core CPU, WiFi, Bluetooth, ADC/DAC, PWM, and multiple communication peripherals.

Espressif ESP32 — IoT SoC
🌐 IoT 📡 Sensors ⚡ ESP32 📟 Arduino 🛠️ Projects 🍇 Pi Project 🖥️ Raspberry Pi 💀 Kali Linux

1️⃣ What is ESP32?

ESP32 is a 32-bit microcontroller with built-in WiFi and Bluetooth.

Key Insight: It is NOT just a microcontroller. It is a complete IoT SoC (System on Chip).

What's Inside ESP32?

🧠
Dual-core CPU
Up to 240 MHz clock speed
📶
WiFi Radio
2.4 GHz 802.11 b/g/n
🔵
Bluetooth
Classic + BLE
💾
RAM + Flash
520KB SRAM + 4MB Flash
📊
ADC / DAC
18 ADC + 2 DAC channels
🔄
PWM
On most GPIO pins
🔌
Peripherals
I2C, SPI, UART, CAN, etc.

2️⃣ ESP32 Architecture (What's Inside?)

🧠 CPU

  • Xtensa 32-bit dual-core processor
  • Up to 240 MHz clock speed
  • 520 KB SRAM internal memory

📶 Wireless

  • 2.4 GHz WiFi (802.11 b/g/n)
  • Bluetooth Classic
  • BLE (Bluetooth Low Energy)

🔌 Peripherals

  • 34 GPIO pins
  • 18 ADC channels (12-bit)
  • 2 DAC channels (8-bit)
  • PWM on most pins
  • 3 UART interfaces
  • 2 I2C interfaces
  • 2 SPI interfaces
  • CAN bus support
  • 10 capacitive touch sensors

3️⃣ Important Things to Check When You Get ESP32

✅ Step 1: Identify USB Chip

Check the USB-to-Serial converter chip on your board and install the correct driver:

USB ChipAction Required
CP2102Install CP2102 driver from Silicon Labs
CH340Install CH340 driver from WCH

✅ Step 2: Check Module Type

Look at the metal shield on the ESP32 module:

Module NameDescription
WROOMNormal module — standard for most projects
WROVERHas external PSRAM — for memory-intensive applications

✅ Step 3: Check Flash Size

The flash memory stores your program. Common sizes:

Flash SizeUsage
4 MBMost common — sufficient for majority of projects
8 MBAdvanced — needed for OTA, large programs, SPIFFS
Tip: You can check flash size using esptool.py flash_id or from the Arduino IDE serial output during upload.

4️⃣ ESP32 Pin Explanation (Very Important)

🔌 Power Pins

PinUse
3V33.3V regulated output
VIN5V input (from USB or external supply)
GNDGround connection
⚠ Warning: ESP32 is 3.3V logic only. Do NOT apply 5V to GPIO pins — it will damage the chip!

📍 GPIO Pins (General Purpose Input/Output)

Here are the important GPIOs and their typical usage:

GPIONotes
2Built-in LED on many boards
4Safe general-purpose output
5SPI SS (Chip Select) — default
12⚠ Boot sensitive — affects flash voltage
14SPI CLK (HSPI)
18SPI SCK (VSPI) — default
19SPI MISO (VSPI) — default
21I2C SDA — default
22I2C SCL — default
23SPI MOSI (VSPI) — default
32–39ADC pins — for analog sensor readings

⚠ Boot Pins (Be Careful!)

These pins affect ESP32 boot behavior. If connected incorrectly, the ESP32 won't start:

PinWhy It's Sensitive
GPIO 0Determines boot mode (must be HIGH for normal boot)
GPIO 2Must be LOW or floating during boot
GPIO 12Selects flash voltage (HIGH = 1.8V, LOW = 3.3V)
GPIO 15Controls boot log output on UART0
⚠ Critical: If these pins are connected wrongly during power-on → ESP32 won't start or will enter download mode instead of running your program.

5️⃣ Communication Protocols (Very Important)

ESP32 supports multiple hardware communication protocols, making it incredibly versatile for IoT projects.

📡 1. UART (Serial Communication)

Used for:

  • → Uploading code to ESP32
  • → Serial Monitor debugging
  • → GPS modules, SIM modules

Default Pins:

SignalPin
TX0GPIO 1
RX0GPIO 3
Serial.begin(115200);

📡 2. I2C (Inter-Integrated Circuit)

Used for:

  • → OLED display (SSD1306)
  • → Temperature sensors (BME280)
  • → Medical sensors (MAX30102)

Default Pins:

SignalPin
SDAGPIO 21
SCLGPIO 22
Wire.begin(21, 22);

📡 3. SPI (Serial Peripheral Interface)

Used for:

  • → SD card module
  • → TFT display
  • → High-speed sensors

Default Pins (VSPI):

SignalPin
SCKGPIO 18
MISOGPIO 19
MOSIGPIO 23
CSGPIO 5

📡 4. PWM (Pulse Width Modulation)

Used for:

  • → Motor speed control
  • → LED brightness dimming
  • → Servo motor control
Note: Almost all GPIO pins on ESP32 support PWM output. ESP32 has 16 independent PWM channels.

📡 5. ADC (Analog to Digital Converter)

Used for:

  • → Reading analog sensors (voltage)
  • → Temperature sensors (LM35)
  • → Biomedical signals (low frequency)

ADC Pins:

GPIO 32–39 (ADC1 channels — recommended)

int value = analogRead(34);
⚠ Note: ADC2 pins (GPIO 0, 2, 4, 12–15, 25–27) cannot be used when WiFi is active. Always use ADC1 (GPIO 32–39) for sensor readings.

📡 6. DAC (Digital to Analog Converter)

Used for:

  • → Signal generation
  • → Analog waveform output
  • → Audio output

Only 2 DAC pins available:

DAC ChannelPin
DAC1GPIO 25
DAC2GPIO 26

📡 7. WiFi

Used for:

  • → Connect to router / internet
  • → Send data to cloud (Firebase, MQTT)
  • → Create Access Point (AP mode)
#include <WiFi.h>

WiFi.begin("SSID", "PASSWORD");

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print(".");
}
Serial.println("Connected!");

📡 8. Bluetooth & BLE

Used for:

  • → Wearable devices
  • → Medical monitoring systems
  • → Phone communication & control
  • → Proximity detection
BLE (Bluetooth Low Energy) is ideal for battery-powered IoT devices. Uses significantly less power than Classic Bluetooth.

6️⃣ Power Modes (Critical for IoT)

Understanding power modes is essential for building battery-powered IoT devices.

ModeCurrent DrawDescription
Active~80–240 mACPU running, WiFi/BT active — full operation
Light Sleep~1 mACPU paused, WiFi maintains connection
Deep Sleep~10 µAOnly RTC memory active — ultra low power

Visual Power Comparison

Active Mode
~80–240 mA
Light Sleep
~1 mA
Deep Sleep
~10 µA

Deep Sleep Code Example

// Sleep for 10 seconds
esp_deep_sleep(10 * 1000000); // value in microseconds
Deep sleep is critical for:
  • 🔋 Battery-powered devices
  • 💓 Medical wearables
  • 🌱 Remote agricultural sensors
  • 📡 Periodic data logging stations

7️⃣ Programming Workflow (Step-by-Step)

Follow these steps to get your ESP32 up and running:

Install Arduino IDE

Download from arduino.cc. Version 2.x recommended.

Install ESP32 Board Package

Go to File → Preferences → Additional Board URLs and add:
https://dl.espressif.com/dl/package_esp32_index.json
Then go to Board Manager and install esp32 by Espressif Systems.

Install USB Driver

Install CP2102 or CH340 driver depending on your board's USB chip.

Select Board

Go to Tools → Board and select "ESP32 Dev Module".

Select COM Port

Go to Tools → Port and select the correct COM port where ESP32 is connected.

Upload Code

Click the Upload button (→). Hold the BOOT button on ESP32 if upload fails.

Use Serial Monitor

Open Tools → Serial Monitor. Set baud rate to 115200 to see output.

8️⃣ Real World Applications

🏥 Medical

  • Remote patient monitoring
  • Neonatal sensor systems
  • Temperature monitoring devices
  • Heart rate & SpO2 logging

🚴 Anti-Theft

  • GPS + WiFi tracker for vehicles
  • BLE tracking tags
  • Motion-triggered alerts

🏠 Smart Home

  • IoT switches & relays
  • Energy monitoring systems
  • Voice-controlled automation
  • Smart lighting

📡 IoT Gateway

  • Send data to Firebase
  • MQTT communication
  • Edge computing node
  • Multi-sensor data aggregation

9️⃣ Important Concepts You Must Know

🔹 Flash vs RAM

  • Flash → Stores your program (non-volatile, persists after power off)
  • RAM (SRAM) → Temporary data while running (lost on power off)

Flash = Hard Drive  |  RAM = Working Memory

🔹 Partition Scheme

Defines how flash memory is divided:

  • App partition → Your program code
  • OTA partition → Over-The-Air update space
  • SPIFFS / LittleFS → File storage
  • NVS → Non-volatile key-value storage

🔹 Pull-up / Pull-down Resistors

Used for stable digital input reading:

  • Pull-up → Default HIGH, button pulls LOW
  • Pull-down → Default LOW, button pulls HIGH
  • ESP32 has internal pull-up/pull-down — use INPUT_PULLUP

🔹 Debouncing

Important for button input:

  • Mechanical buttons "bounce" — give multiple signals on one press
  • Software debounce: add small delay (~50ms) after button read
  • Hardware debounce: use capacitor across button

🔟 Safe Pin Usage (Quick Reference)

✅ Safe Output Pins

These GPIO pins can be used safely for general-purpose output:

GPIO 4 GPIO 5 GPIO 18 GPIO 19 GPIO 21 GPIO 22 GPIO 23 GPIO 25 GPIO 26 GPIO 27 GPIO 32 GPIO 33

⚠ Avoid for Beginners

These pins affect boot and can cause issues if used incorrectly:

GPIO 0 GPIO 2 GPIO 12 GPIO 15

🧠 Advanced View — For Your Level

If you're working in Medical Tech, Sensor Fusion, mmWave + IoT, ESP32 can:

📊
Collect sensor data
From multiple sensors simultaneously via I2C, SPI, ADC
⚙️
Preprocess signals
Filter, average, and prepare data before transmission
☁️
Send to cloud
WiFi → Firebase, AWS IoT, ThingSpeak, MQTT
😴
Deep sleep mode
Wake periodically, read sensors, send data, sleep again
🤖
Run lightweight ML (TinyML)
On-device inference for anomaly detection, gesture recognition

🎯 Final Summary

ESP32 is a powerful, all-in-one IoT chip:

✔ Microcontroller ✔ WiFi + Bluetooth ✔ Multiple Protocols ✔ ADC / DAC ✔ Low Power Capable ✔ IoT Ready
FeatureDetails
CPUDual-core Xtensa, up to 240 MHz
RAM520 KB SRAM
Flash4 MB (typical)
WiFi2.4 GHz 802.11 b/g/n
BluetoothClassic + BLE 4.2
GPIO34 pins
ADC18 channels (12-bit)
DAC2 channels (8-bit)
ProtocolsUART, I2C, SPI, CAN, PWM
Deep Sleep~10 µA
Voltage3.3V logic (5V input via VIN)
Bottom Line: ESP32 is the go-to chip for any IoT project — from simple home automation to complex medical wearables and sensor fusion systems. Master its pins, protocols, and power modes, and you can build almost anything.