Extra 5% OFF Use Code: OL05
Free Shipping over ₹999

ESP32 Pinout reference

Introduction:

One of the key benefits of the ESP32 is its numerous GPIOs, providing many more options than the ESP8266. This abundance allows for more straightforward connections without the need to constantly manage or share pins. However, to fully leverage this feature, it’s crucial to thoroughly examine the pinout details. By doing so, you can ensure a seamless and efficient setup for your projects. Enjoy exploring the possibilities!

Note:
Please note that the following pinout reference is for the popular 30-pin ESP32 dev board development board.

ESP32 Peripherals and I/O

The ESP32 boasts a total of 48 GPIO pins, although only 25 of these are accessible via the pin headers on both sides of the development board. These pins support a wide range of peripheral functions, including:

  • 15 ADC Channels: These 15 channels feature a 12-bit SAR ADC with selectable ranges of 0-1V, 0-1.4V, 0-2V, or 0-4V.
  • 2 UART Interfaces: Two UART interfaces come with flow control and IrDA support for serial communication.
  • 25 PWM Outputs: With 25 PWM pins, you can easily control devices such as motor speed controllers or LED brightness.
  • 2 DAC Channels: Two 8-bit DACs allow for generating true analog voltages.
  • SPI, I2C, and I2S Interfaces: The ESP32 includes three SPI interfaces, one I2C interface for connecting sensors and peripherals, and two I2S interfaces for audio projects.
  • 9 Touch Pads: Nine GPIOs are equipped with capacitive touch sensing capabilities.

The ESP32’s pin multiplexing feature enhances its versatility, allowing multiple peripherals to share a single GPIO pin. For instance, a single GPIO pin can function as an ADC input, DAC output, or touch pad, depending on your project needs.

ESP32 Pinout

The pinout is as follow:

GPIO pin

The ESP32-WROOM-32 module features 25 GPIO pins, each capable of being assigned various functions through appropriate register programming. These GPIOs come in different types, including digital-only, analog-enabled, and capacitive-touch-enabled, among others. Most digital GPIOs can be configured with internal pull-up or pull-down resistors or set to high impedance.

Which GPIOs are safe to use?

While the ESP32 module offers numerous pins with various functions, some may not be ideal for your projects. Below is a breakdown of which pins are safe to use and which ones require caution.

🔵 Your top priority pins. They are perfectly safe to use.

⚠️ Pay close attention because their behavior, particularly during boot, can be unpredictable. Use them only when absolutely necessary.

❌ It is recommended that you avoid using these pins.

PinPin LabelGPIOSafe to useReason
4SENSOR_VPGPIO36⚠️Input only GPIO, cannot be configured as output
5SENSOR_VNGPIO39⚠️Input only GPIO, cannot be configured as output
6IO34GPIO34⚠️Input only GPIO, cannot be configured as output
7IO35GPIO35⚠️Input only GPIO, cannot be configured as output
8IO32GPIO32✔️Safe to use
9IO33GPIO33✔️Safe to use
10IO25GPIO25✔️Safe to use
11IO26GPIO26✔️Safe to use
12IO27GPIO27✔️Safe to use
13IO14GPIO14✔️Safe to use
14IO12GPIO12⚠️Must be LOW during boot
16IO13GPIO13✔️Safe to use
17SHD/SD2GPIO9Connected to Flash memory
18SWP/SD3GPIO10Connected to Flash memory
19SCS/CMDGPIO11Connected to Flash memory
20SCK/CLKGPIO6Connected to Flash memory
21SDO/SD0GPIO7Connected to Flash memory
22SDI/SD1GPIO8Connected to Flash memory
23IO15GPIO15⚠️Must be HIGH during boot, prevents startup log if pulled LOW
24IO2GPIO2⚠️Must be LOW during boot and also connected to the onboard LED
25IO0GPIO0⚠️Must be HIGH during boot and LOW for programming
26IO4GPIO4✔️Safe to use
27IO16GPIO16✔️Safe to use
28IO17GPIO17✔️Safe to use
29IO5GPIO5⚠️Must be HIGH during boot
30IO18GPIO18✔️Safe to use
31IO19GPIO19✔️Safe to use
33IO21GPIO21✔️Safe to use
34RXD0GPIO3Rx pin, used for flashing and debugging
35TXD0GPIO1Tx pin, used for flashing and debugging
36IO22GPIO22✔️Safe to use
37IO23GPIO23✔️Safe to use

Input-Only GPIOs

GPIO pins 4, 5, 6, and 7 are designated as input-only pins, meaning they cannot be configured as outputs. These pins are primarily used for digital or analog input functions, or for other specific purposes. Unlike other GPIO pins, they do not have internal pull-up or pull-down resistors.


ADC Pins on ESP32

The ESP32-WROOM-32 module features two ADC (Analog to Digital Converter) blocks: ADC1 and ADC2. Each block has multiple channels:

ADC1: This block contains 6 channels, labeled as ADC1_CH0 and ADC1_CH3 to ADC1_CH7.

ADC2: Here, you’ll find 9 channels, labeled as ADC2_CH0 to ADC2_CH9.

The ADCs on the ESP32 can be configured with a resolution of up to 12 bits. This means they can detect 4096 discrete analog levels. With an operating voltage of 3.3 V, this translates to a resolution of 0.0008 volts (or 0.8 mV) per unit.

Warning:
When Wi-Fi is in use, ADC2 pins are not available for utilization. If you encounter
difficulties retrieving values from an ADC2 GPIO while using Wi-Fi, opting for an ADC1 GPIO instead is recommended. This switch should address the issue you're facing.

DAC Pins

The ESP32 features two 8-bit DAC (Digital-to-Analog Converter) channels, located on GPIO25 and GPIO26. These DAC pins can convert digital signals into analog voltages, making them useful for generating simple audio signals, such as beeps or tones.

.

Note:
However, due to their 8-bit resolution and relatively low sampling rate, these DAC pins are not ideal for high-quality audio applications. The limited resolution can result in noticeable quantization noise and lower fidelity, which is unsuitable for more complex or high-fidelity audio output. For better audio performance, external DACs or the I2S interface, which supports higher bit depth and sampling rates, are recommended

Touch Pins

The ESP32 is equipped with capacitive touch sensing capabilities, featuring 10 touch-sensitive GPIO pins:

  • T0: GPIO4
  • T1: GPIO0 (Note: Not all ESP32 development boards expose this pin)
  • T2: GPIO2
  • T3: GPIO15
  • T4: GPIO13
  • T5: GPIO12
  • T6: GPIO14
  • T7: GPIO27
  • T8: GPIO33
  • T9: GPIO32

These touch pins can detect changes in capacitance caused by a touch, making them ideal for creating touch-based interfaces, such as buttons, sliders, or touchpads.

Note:
Not all ESP32 development boards expose GPIO0 pin

The touch sensors work by measuring the capacitance on each pin and detecting variations when an object, like a human finger, comes into proximity or contact with the sensor. This feature is especially useful for building user interfaces, home automation systems, or any project requiring touch input without mechanical components.

The touch pins are simple to configure and use within the ESP-IDF or Arduino IDE environments, allowing developers to easily integrate touch functionality into their projects.

I2C Pins

The ESP32 supports the I2C (Inter-Integrated Circuit) communication protocol, which is widely used for connecting sensors, displays, and other peripherals. The ESP32 can have multiple I2C buses, and you can configure any GPIO pins for SCL (clock) and SDA (data) lines, making it highly flexible for various hardware setups.

By default, many development boards and libraries use the following GPIO pins for I2C:

  • SCL (Clock): GPIO22
  • SDA (Data): GPIO21

However, these default pins can be changed to any other GPIO pins if needed, providing great flexibility depending on the requirements of your project.

Configuring I2C Pins

To configure the I2C pins in your code, you can specify the desired GPIOs when initializing the I2C bus. Here is an example in Arduino IDE:

#include <Wire.h>

#define I2C_SDA 21
#define I2C_SCL 22

void setup() {
  Wire.begin(I2C_SDA, I2C_SCL);
  Serial.begin(115200);
  Serial.println("I2C initialized");
}

void loop() {
  // Your I2C code here
}

Applications

I2C is used for a variety of applications, including:

  • Connecting sensors: Such as temperature, humidity, and motion sensors.
  • Interfacing displays: Like OLED and LCD screens.
  • Communicating with EEPROMs: For data storage.
  • Connecting RTC modules: For real-time clock functionalities.

SPI Pins

The ESP32 supports the SPI (Serial Peripheral Interface) communication protocol, which is widely used for high-speed data transfer between the microcontroller and peripherals like sensors, displays, and memory cards. The ESP32 has multiple SPI interfaces (SPI0, SPI1, and HSPI) that can be configured to use different GPIO pins.

By default, many development boards and libraries use the following GPIO pins for SPI:

  • SPI MOSI (Master Out Slave In): GPIO23
  • SPI MISO (Master In Slave Out): GPIO19
  • SPI SCLK (Serial Clock): GPIO18
  • SPI CS (Chip Select): GPIO5
Configuring SPI Pins

To configure the SPI pins, you can specify the desired GPIOs when initializing the SPI bus. Here is an example in Arduino IDE:

#include <SPI.h>

#define SPI_MOSI 23
#define SPI_MISO 19
#define SPI_SCLK 18
#define SPI_CS 5

void setup() {
  // Start the SPI bus
  SPI.begin(SPI_SCLK, SPI_MISO, SPI_MOSI, SPI_CS);
  Serial.begin(115200);
  Serial.println("SPI initialized");
}

void loop() {
  // Your SPI code here
}

Applications

SPI is used for a variety of applications, including:

  • Connecting sensors: Such as accelerometers, gyroscopes, and digital thermometers.
  • Interfacing displays: Like TFT and OLED screens.
  • Communicating with memory cards: Such as SD cards for data storage.
  • Connecting wireless modules: Like Wi-Fi and Bluetooth transceivers.

PWM Pin

The ESP32 supports up to 16 independent PWM channels, and these channels can be mapped to various GPIO pins. Most GPIO pins on the ESP32 can be configured as PWM outputs, with the exception of pins that are dedicated as input-only or reserved for specific functions.

ESP32 PWM Channels and Pins
  • PWM Channels: The ESP32 provides up to 16 PWM channels, allowing for flexible control of various devices.
  • GPIO Pins: Almost all GPIO pins can be used for PWM output, giving you broad flexibility in selecting which pins to use. However, some pins are reserved for specific functions or are input-only and cannot be used for PWM.
Common Uses of PWM
  • LED Dimming: Adjust brightness by changing the duty cycle.
  • Motor Speed Control: Regulate speed or direction of DC motors and servos.
  • Signal Generation: Produce various waveforms for communication or testing.
  • Audio Signals: Generate tones or other audio signals for alarms and sound effects.

UART Pins

The ESP32 microcontroller features multiple UART (Universal Asynchronous Receiver/Transmitter) interfaces, making it highly versatile for serial communication tasks. UART is widely used for connecting the ESP32 to various devices, such as GPS modules, Bluetooth modules, serial consoles, and other microcontrollers. The ESP32 has three UART interfaces: UART0, UART1, and UART2.

Note:
it's important to note that UART1 pins are generally used for the integrated flash memory chip, so they are typically not available for general use. 
Default UART Pins
  • UART0:
    • TX (Transmit): GPIO1
    • RX (Receive): GPIO3
    • Use: Commonly used for serial communication with the USB-to-serial converter for programming and debugging.

  • UART1:
    • TX (Transmit): GPIO10 (SD2)
    • RX (Receive): GPIO9 (SD3)
    • Note: These pins are generally used for the integrated flash memory chip and are not recommended for general-purpose use.

  • UART2:
    • TX (Transmit): GPIO17
    • RX (Receive): GPIO16
    • Use: Can be used for additional serial communication needs.
Configuring UART Pins

You can remap the UART pins to other GPIOs if needed. Here’s an example of how to configure and use UART in the Arduino IDE:

#include <HardwareSerial.h>

// Create an instance of the hardware serial
HardwareSerial MySerial(2); // Using UART2

void setup() {
  // Initialize UART2 at a baud rate of 115200
  MySerial.begin(115200, SERIAL_8N1, 16, 17); // RX on GPIO16, TX on GPIO17
  Serial.begin(115200); // Use UART0 for debugging
}

void loop() {
  if (MySerial.available()) {
    // Read data from UART2 and print it to the Serial Monitor
    Serial.write(MySerial.read());
  }

  if (Serial.available()) {
    // Read data from the Serial Monitor and send it over UART2
    MySerial.write(Serial.read());
  }
}

RTC GPIO Pins

The ESP32 includes RTC pins that are part of its power management and low-power operation features. These RTC pins are connected to the ESP32’s RTC controller, which operates even when the main processor is in deep sleep mode, allowing the chip to wake up and perform tasks at scheduled times.

  • RTC_GPIO0 (GPIO36)
  • RTC_GPIO3 (GPIO39)
  • RTC_GPIO4 (GPIO34)
  • RTC_GPIO5 (GPIO35)
  • RTC_GPIO6 (GPIO25)
  • RTC_GPIO7 (GPIO26)
  • RTC_GPIO8 (GPIO33)
  • RTC_GPIO9 (GPIO32)
  • RTC_GPIO10 (GPIO4)
  • RTC_GPIO11 (GPIO0)
  • RTC_GPIO12 (GPIO2)
  • RTC_GPIO13 (GPIO15)
  • RTC_GPIO14 (GPIO13)
  • RTC_GPIO15 (GPIO12)
  • RTC_GPIO16 (GPIO14)
  • RTC_GPIO17 (GPIO27)

Strapping Pins

Strapping pins on the ESP32 are GPIO pins that are sampled during the chip’s reset and determine the bootloader mode or flashing mode.

  • GPIO 0 (must be LOW to enter boot mode)
  • GPIO 2 (must be floating or LOW during boot)
  • GPIO 5 (must be HIGH during boot)
  • GPIO 12 (must be LOW during boot)
  • GPIO 15 (must be HIGH during boot)

These strapping pins determine whether the ESP32 enters BOOT mode (to execute the program stored in flash memory) or FLASH mode (to upload a new program to the flash memory) when the device is powered on. The state of these pins at startup dictates which mode the ESP32 will enter.

For most development boards with integrated USB-to-Serial converters, you usually don’t need to manually manage these pins. The board automatically configures them for either flashing or booting, depending on the task at hand.

However, if you have peripherals connected to these strapping pins, they might interfere with the ESP32’s ability to enter the correct mode for flashing or booting. This can lead to problems when you try to upload new code or firmware, as the peripherals could prevent the ESP32 from setting the pins correctly.

After the reset, these strapping pins resume their normal functions, but it’s important to handle them carefully to avoid any issues during the boot or flashing process.

Power Pins

The ESP32 has two main power pins: the VIN pin and the 3V3 pin.

  • VIN Pin: This pin can be used to supply power directly to the ESP32 and its peripherals when connected to a regulated 5V power source.
  • 3V3 Pin: This pin provides a 3.3V output from the onboard voltage regulator, capable of supplying up to 600mA of current.
  • GND Pin: The GND pin serves as the ground connection.

These power options allow flexibility in powering your ESP32 and connected components.

ENABLE Pin

Enable (EN) is the 3.3V regulator’s enable pin. It’s pulled up, so connect to ground to disable the 3.3V regulator. This means that you can use this pin connected to a pushbutton to restart your ESP32, for example.

Comment (1)

Leave a Reply

Your email address will not be published.

Need Help?