Understanding ESP32 GPIO
The ESP32 exposes up to 34 GPIO pins, though not all of them are available on every development board. Each pin can serve multiple functions — from basic digital I/O to PWM output, ADC input, and communication buses. Knowing which pin does what is essential to avoid hardware conflicts and unexpected behavior.
Input-Only Pins
GPIO 34, 35, 36, and 39 are input-only — they have no internal pull-up or pull-down resistors and cannot be used as outputs. They are ideal for reading analog signals or digital inputs when output capability isn't needed.
ADC (Analog-to-Digital Converter) Pins
The ESP32 has two ADC units:
- ADC1 (8 channels): GPIO 32–39 — safe to use even when Wi-Fi is active
- ADC2 (10 channels): GPIO 0, 2, 4, 12–15, 25–27 — cannot be used when Wi-Fi is active
This is one of the most common pitfalls for beginners. If your analog reads return garbage values while Wi-Fi is on, switch to an ADC1 pin.
PWM Output
Almost any GPIO can output PWM via the ESP32's LEDC peripheral, which provides 16 independent PWM channels. This is more flexible than most AVR-based Arduinos, where PWM is limited to specific pins. Common uses include LED dimming, motor speed control, and servo signals.
Touch-Sensitive Pins
The ESP32 has 10 capacitive touch pins: GPIO 0, 2, 4, 12, 13, 14, 15, 27, 32, and 33. These can detect a human finger touch without any additional hardware, enabling touchpad interfaces, wake-from-sleep triggers, and interactive controls.
Strapping Pins — Use With Caution
Certain GPIO pins are read by the ESP32 during boot to determine the operating mode. Incorrect voltages on these pins can prevent the chip from booting or put it into an unintended mode:
| Pin | Boot Behavior | Recommendation |
|---|---|---|
| GPIO 0 | LOW = flash mode | Avoid pulling LOW at boot |
| GPIO 2 | Must be LOW to enter download mode | Leave floating or use onboard LED carefully |
| GPIO 12 | Sets flash voltage | Leave floating on most boards |
| GPIO 15 | Enables boot log output | Pull HIGH to suppress UART debug noise |
Communication Interfaces
The ESP32 supports flexible pin mapping for its communication buses:
- UART (3 ports): Default TX/RX on GPIO 1/3 (used by USB), UART2 on GPIO 16/17
- I2C: Default SDA on GPIO 21, SCL on GPIO 22 (remappable)
- SPI: VSPI on GPIO 18 (CLK), 19 (MISO), 23 (MOSI), 5 (CS)
- I2S: Flexible pin assignment for audio applications
Power Pins
- 3.3V: Output from onboard regulator — do not exceed 300 mA draw
- 5V (VIN): Input to onboard regulator on DevKit boards
- GND: Common ground — multiple GND pins are available
- EN (ENABLE): Pull LOW to reset the chip
Quick Reference Tips
- Avoid GPIO 6–11 — these are connected to the internal flash memory and must not be used.
- Use ADC1 pins only when Wi-Fi is enabled.
- Always check strapping pin states if the board won't boot after wiring peripherals.
- Most GPIO pins support internal pull-up and pull-down resistors configurable in software.