Ugenz Academy/IoT Tutorial

Esp32 Pinout And Gpio

16 min read3,074 words

Reading progress

Keep learning

ESP32 — Pinout and GPIO

This is one of the most important ESP32 topics because almost every practical project involves connecting something to an ESP32 pin.

After this topic, you should understand:

  • What a pin is
  • What GPIO means
  • GPIO numbering
  • Input and output
  • Power pins
  • GND
  • ADC pins
  • PWM
  • Communication pins
  • Input-only pins
  • Boot/strapping pins
  • Safe and unsafe pin usage
  • How to select pins for a project

1. What Is a Pin?

A pin is an electrical connection on the ESP32 board.

You connect external components to these pins.

For example:

ESP32 │ ├── LED ├── Button ├── Sensor ├── Relay ├── Servo ├── Motor Driver ├── LCD └── RFID

A typical ESP32 development board has pins along its sides:

ESP32 DEV BOARD ┌───────────────────┐ 3V3 ── │ │ ── GND GND ── │ │ ── GPIO23 GPIO36 │ │ ── GPIO22 GPIO39 │ │ ── GPIO21 GPIO34 │ │ ── GPIO19 GPIO35 │ │ ── GPIO18 GPIO32 │ │ ── GPIO5 GPIO33 │ │ ── GPIO17 GPIO25 │ │ ── GPIO16 GPIO26 │ │ ── GPIO4 GPIO27 │ │ ── GPIO2 GPIO14 │ │ ── GPIO15 GPIO12 │ │ GPIO13 │ │ └───────────────────┘

Important: This is only a conceptual example. Exact pins and labels depend on your ESP32 board/variant.


2. What Does GPIO Mean?

GPIO stands for:

General Purpose Input/Output

It means a GPIO can be used to communicate with external electronic devices.

Input

ESP32 receives information.

Button ─────→ ESP32

Output

ESP32 sends a signal.

ESP32 ─────→ LED

So:

GPIO │ ┌─────┴─────┐ ↓ ↓ INPUT OUTPUT │ │ Button LED Sensor Relay PIR Buzzer

3. GPIO as an Input

Suppose you connect a push button.

Button │ ↓ GPIO │ ESP32

The ESP32 can read whether the button is pressed.

Example:

int state = digitalRead(18);

The result is generally:

HIGH

or:

LOW

4. GPIO as an Output

Now connect an LED.

ESP32 GPIO │ ↓ LED

The ESP32 can control the LED.

Example:

digitalWrite(2, HIGH);

and:

digitalWrite(2, LOW);

Conceptually:

HIGH → Output active LOW → Output inactive

The exact electrical behavior depends on how the circuit is wired.


5. GPIO Number vs Physical Pin

This is very important.

Suppose you see:

GPIO 25

That doesn't mean "pin number 25" physically.

It means:

The GPIO identifier is 25.

The physical position of that pin on the development board depends on the board design.

For example:

Physical Header Position ↓ [Pin] ↓ GPIO25

Therefore, always distinguish:

GPIO Number ≠ Physical Header Position

6. pinMode()

Before using a GPIO as a digital input or output, you commonly configure it.

Output

pinMode(2, OUTPUT);

Input

pinMode(18, INPUT);

Input with internal pull-up

pinMode(18, INPUT_PULLUP);

The third option is very useful for buttons.

We'll study pull-ups and pull-downs more deeply later.


7. digitalRead()

Use digitalRead() to read a digital input.

Example:

int buttonState = digitalRead(18);

Conceptually:

Button ↓ GPIO18 ↓ digitalRead() ↓ HIGH / LOW

8. digitalWrite()

Use digitalWrite() to control a digital output.

Example:

digitalWrite(2, HIGH);

or:

digitalWrite(2, LOW);

Example LED program:

#define LED_PIN 2 void setup() { pinMode(LED_PIN, OUTPUT); } void loop() { digitalWrite(LED_PIN, HIGH); delay(1000); digitalWrite(LED_PIN, LOW); delay(1000); }

This creates a simple blinking output.


9. Power Pins

Not every pin is a GPIO.

Some pins are intended for power.

Common labels include:

3V3 GND VIN 5V

The exact names and behavior vary by board.


10. 3V3 Pin

3V3 generally refers to the board's approximately 3.3 V supply rail.

It can be used to power suitable low-current 3.3 V components.

For example:

ESP32 3V3 │ ├──── Sensor VCC │ └──── OLED VCC

But don't assume the 3V3 pin can supply unlimited current.

Always check your board and peripheral requirements.


11. GND

GND = Ground

Ground provides the common electrical reference for the circuit.

For many projects, the ESP32 and external modules need a common ground.

For example:

ESP32 GND ───────── Sensor GND │ ├────────── Relay GND │ └────────── Motor Driver GND

This is especially important when using an external power supply.


12. Common Ground

Suppose you have:

ESP32 External Power Supply Motor Driver

You often need a common ground reference:

ESP32 GND │ │ ├──────── Motor Driver GND │ └──────── External Supply GND

However, the correct grounding arrangement depends on the circuit and power architecture.

Never connect different power sources together blindly.


13. VIN / 5V

Some ESP32 development boards expose a pin labeled:

VIN

or:

5V

The exact meaning varies between boards.

On some boards, it is connected to the USB 5 V rail; on others, it may be intended as an external input.

Therefore:

Never assume every ESP32 board's VIN pin works the same way.

Always check the board's documentation/schematic before applying external power.


14. 3.3 V Logic

ESP32 GPIO logic is generally based around 3.3 V.

This is one of the most important electrical concepts.

For example:

ESP32 GPIO │ │ 3.3 V logic ↓ 3.3 V-compatible sensor

Be careful with modules that output 5 V logic.

A 5 V supply and a 5 V signal are not the same thing as a 3.3 V signal.

For example:

5V sensor output │ ↓ Level shifting │ ↓ ESP32 GPIO

A level shifter or appropriate voltage-divider/interface may be required depending on the signal.


15. ADC Pins

ADC means:

Analog-to-Digital Converter

ADC allows the ESP32 to measure analog voltages and convert them into numerical values.

For example:

LDR │ │ Analog voltage ↓ ESP32 ADC │ ↓ Digital value

This is useful for:

  • LDR
  • Potentiometer
  • Analog sensors
  • Gas sensors
  • Analog voltage measurements

Example:

int value = analogRead(34);

The exact ADC resolution/range and usable pins depend on the ESP32 variant and configuration.


16. Input-Only Pins

On the classic ESP32, some GPIOs are input-only.

A commonly encountered group is:

GPIO34 GPIO35 GPIO36 GPIO39

These are useful for reading signals.

For example:

Sensor │ ↓ GPIO34 ↓ ESP32

But you cannot treat GPIO34 like a normal output pin on the original ESP32.

For example, don't expect:

pinMode(34, OUTPUT);

to give you a normal output.

This is a good example of why the exact ESP32 variant matters.


17. ADC1 and ADC2 on Classic ESP32

On the original ESP32, ADC pins are divided into ADC1 and ADC2 groups.

This becomes important when using Wi-Fi.

A common practical rule is:

ADC2 has limitations when Wi-Fi is active on the classic ESP32.

Therefore, if your project needs:

Analog sensor + Wi-Fi

ADC1 pins are often preferred.

This is a classic ESP32-specific detail; newer ESP32 variants can differ.


18. PWM

PWM stands for:

Pulse Width Modulation

PWM allows you to control things such as:

  • LED brightness
  • Motor speed
  • Servo control
  • Other devices requiring timed output signals

Conceptually:

HIGH ────┐ ┌────┐ ┌──── │ │ │ │ LOW └────┘ └────┘

By changing the duty cycle:

25% → Low average output 50% → Medium 75% → Higher

ESP32 provides flexible PWM through its LEDC peripheral.

We'll study ADC, DAC and PWM in detail in a later topic.


19. Communication Pins

Some ESP32 GPIOs can be used for communication protocols.

Common interfaces include:

UART

ESP32 TX ─────→ Device RX ESP32 RX ←───── Device TX GND ─────────── GND

I²C

Usually:

SDA SCL

SPI

Common signals include:

MOSI MISO SCLK CS

The exact GPIO assignments can often be configured depending on the ESP32 variant and framework.


20. GPIO Multiplexing

One of the powerful features of ESP32 is that many GPIOs can have multiple functions.

For example, a GPIO might be used for:

GPIO │ ├── Digital I/O ├── PWM ├── UART ├── SPI ├── I²C └── Other peripheral functions

This is called pin multiplexing or GPIO matrix/peripheral routing in ESP32 terminology.

So a pin isn't necessarily permanently dedicated to only one function.


21. Boot / Strapping Pins

Some GPIOs have special functions during startup.

These are often called:

Strapping pins

Their electrical state during reset/boot can affect how the ESP32 starts.

This means a connected sensor, relay, button, or other circuit can sometimes interfere with booting if it forces the pin into an unexpected state.

Conceptually:

Power ON ↓ ESP32 checks boot configuration ↓ Boot mode selected ↓ Program starts

Therefore, you should be careful when using certain GPIOs for external hardware.


22. GPIO0

On many classic ESP32 development boards, GPIO0 is associated with the boot/download process.

That's why many boards have:

BOOT → GPIO0

Pressing BOOT during reset/upload can place the chip into a programming/download mode.

Don't connect hardware to such pins without understanding their startup behavior.


23. GPIO2

GPIO2 is commonly seen on ESP32 boards and is often connected to an onboard LED on some boards.

It can be useful for basic LED demonstrations.

However, GPIO2 can also have boot-related considerations on certain ESP32 designs.

So:

GPIO2

is not automatically "the LED pin" on every ESP32 board.


24. GPIO12

On the original ESP32, GPIO12 is a strapping pin and can have important boot-related behavior.

Therefore, blindly connecting external circuits to it can cause startup problems in some configurations.

This is an example of:

A pin that may work normally during runtime but can still affect boot behavior.


25. GPIO15

GPIO15 is another pin that can have boot/strapping considerations on classic ESP32 designs.

Again, the exact behavior depends on the chip and board.

This is why a pinout diagram alone isn't enough—you should understand the board's boot requirements.


26. Pins Commonly Used for Flash/PSRAM

Some ESP32 variants/modules internally use certain GPIOs for external flash or PSRAM.

Those pins may not be available as ordinary user GPIOs.

For example, on some ESP32 modules, pins associated with internal memory interfaces should not be used as normal external connections.

The exact list depends on the ESP32 variant/module.


27. Safe GPIO Selection

For a beginner project, you generally want pins that:

  • Are exposed on your board
  • Support the required function
  • Are not input-only if you need output
  • Are not reserved for flash/PSRAM
  • Don't interfere with boot
  • Match the required voltage
  • Are supported by your specific ESP32 variant

Think:

Choose GPIO │ ┌─────┴─────┐ ↓ ↓ Required? Boot-safe? │ │ └─────┬─────┘ ↓ Check board pinout ↓ Use it

28. Example: Connecting an LED

Suppose you want to connect an LED.

ESP32 GPIO │ Resistor │ LED │ GND

Code:

#define LED_PIN 25 void setup() { pinMode(LED_PIN, OUTPUT); } void loop() { digitalWrite(LED_PIN, HIGH); delay(1000); digitalWrite(LED_PIN, LOW); delay(1000); }

Here:

GPIO25 → Output

The ESP32 controls the LED.


29. Example: Button Input

Suppose a button is connected to GPIO18.

Button │ GPIO18 │ ESP32

Code:

#define BUTTON_PIN 18 void setup() { pinMode(BUTTON_PIN, INPUT_PULLUP); } void loop() { int state = digitalRead(BUTTON_PIN); if (state == LOW) { // Button pressed } }

With INPUT_PULLUP, the logic is commonly:

Button released → HIGH Button pressed → LOW

because the internal pull-up holds the input high and the button connects it to ground when pressed.


30. Example: Relay

Suppose a relay module's control input is connected to GPIO26.

ESP32 GPIO26 │ ↓ Relay IN

Code:

#define RELAY_PIN 26 void setup() { pinMode(RELAY_PIN, OUTPUT); } void loop() { digitalWrite(RELAY_PIN, HIGH); delay(2000); digitalWrite(RELAY_PIN, LOW); delay(2000); }

Important: Some relay modules are active LOW.

That means:

LOW → Relay ON HIGH → Relay OFF

So the behavior depends on the relay module.


31. Example: Ultrasonic Sensor

Suppose an ultrasonic sensor has:

VCC GND TRIG ECHO

You might connect:

ESP32 GPIO5 → TRIG ESP32 GPIO18 → ECHO

But there is an important warning:

Many common HC-SR04 modules can output approximately 5 V on ECHO.

Because ESP32 GPIOs are 3.3 V logic, you should not blindly connect a 5 V ECHO signal directly.

Use an appropriate level-shifting/voltage-divider circuit.

Conceptually:

HC-SR04 ECHO │ ↓ Voltage Divider / Level Shifter │ ↓ ESP32 GPIO

This is an excellent example of why understanding GPIO electrical characteristics matters.


32. ESP32 GPIO Current

A GPIO pin is designed for logic-level signaling, not for powering large loads.

Don't do this:

ESP32 GPIO │ └────── Motor ❌

or:

ESP32 GPIO │ └────── High-power lamp ❌

Instead:

ESP32 GPIO │ ↓ Driver / Relay / MOSFET / Motor Driver │ ↓ External Power │ ↓ Load

The GPIO controls the driver; the driver handles the load.


33. Motors Need Special Attention

For a motor project:

ESP32 │ │ control signals ↓ Motor Driver │ │ power ↓ Motor

For example, with an L298N:

ESP32 GPIO18 ──→ IN1 ESP32 GPIO19 ──→ IN2 ESP32 GPIO21 ──→ IN3 ESP32 GPIO22 ──→ IN4

The motor should be powered through the motor driver and appropriate external supply, not directly from the ESP32 GPIO.


34. GPIO Naming in Code

There are several ways to write a pin number.

For example:

digitalWrite(25, HIGH);

But a better practice is often:

#define LED_PIN 25 digitalWrite(LED_PIN, HIGH);

Or:

const int LED_PIN = 25;

This makes your code easier to understand.

Instead of:

digitalWrite(25, HIGH); digitalWrite(25, LOW);

you can write:

digitalWrite(LED_PIN, HIGH); digitalWrite(LED_PIN, LOW);

35. A Simple Pin Classification

For a classic ESP32, you can mentally divide pins like this:

ESP32 GPIO │ ├── General Digital I/O │ ├── ADC-capable │ ├── Input-only │ ├── PWM-capable │ ├── Communication-capable │ ├── Boot/strapping-sensitive │ └── Memory-reserved

A single GPIO may belong to multiple categories.

For example:

GPIO25 ├── Digital I/O ├── ADC-capable └── PWM-capable

The exact capabilities depend on the ESP32 family.


36. Don't Memorize One Pinout for Every ESP32

This is perhaps the most important lesson from this topic.

You may find a pinout online showing:

GPIO 25 GPIO 26 GPIO 27 GPIO 32 GPIO 33 ...

That pinout may be correct for a particular classic ESP32 board.

But it doesn't mean the same thing for:

ESP32-S3 ESP32-C3 ESP32-C6 ESP32-H2

Different chips have different GPIO layouts and capabilities.

Therefore:

Always identify the exact ESP32 variant and board before choosing GPIOs.


37. A Practical Pin-Selection Example

Suppose your project requires:

1 LED 1 Button 1 LDR 1 Servo 1 I²C LCD

You might conceptually allocate:

LED → Digital output Button → Digital input LDR → ADC input Servo → PWM-capable output LCD → SDA + SCL

The important thing isn't just choosing random GPIO numbers.

You first identify the required function, then select compatible pins.

Component ↓ Required signal type ↓ Find suitable GPIO ↓ Check boot restrictions ↓ Check voltage ↓ Connect

38. Pinout Cheat Sheet

For a typical classic ESP32 DevKit-style board, you may encounter:

Pin/GroupTypical Use
3V33.3 V power
GNDGround
VIN/5VBoard-dependent power rail
GPIO0Boot/strapping-sensitive
GPIO2Digital I/O, boot considerations
GPIO4General I/O
GPIO5General I/O, SPI-related use
GPIO12Boot/strapping-sensitive
GPIO13General I/O
GPIO14General I/O
GPIO15Boot/strapping-sensitive
GPIO16General I/O
GPIO17General I/O
GPIO18General I/O, SPI-related
GPIO19General I/O, SPI-related
GPIO21General I/O, commonly I²C SDA
GPIO22General I/O, commonly I²C SCL
GPIO23General I/O, SPI-related
GPIO25General I/O, DAC/ADC/PWM on classic ESP32
GPIO26General I/O, DAC/ADC/PWM on classic ESP32
GPIO27General I/O
GPIO32GPIO/ADC
GPIO33GPIO/ADC
GPIO34Input-only, ADC
GPIO35Input-only, ADC
GPIO36Input-only, ADC
GPIO39Input-only, ADC

This table is for the classic ESP32 family and is not a universal pinout for every ESP32 board.


39. The Golden Rules of ESP32 GPIO

Remember these rules:

Rule 1

GPIO is for logic, not high-power loads.

Rule 2

ESP32 GPIO logic is generally 3.3 V.

Rule 3

Always connect a common ground when required by the circuit.

Rule 4

Don't assume every GPIO can perform every function.

Rule 5

Some GPIOs are input-only.

Rule 6

Some GPIOs affect boot mode.

Rule 7

Some pins may be reserved for internal flash/PSRAM.

Rule 8

Don't blindly connect 5 V signals to ESP32 GPIOs.

Rule 9

Don't power motors directly from GPIO pins.

Rule 10

Always check the exact ESP32 board's pinout.


40. Final Mental Model

Think of an ESP32 board like a small control center:

ESP32 │ ┌───────────────────┼───────────────────┐ │ │ │ INPUT PROCESS OUTPUT │ │ │ │ CPU │ │ │ │ ┌───┼────┐ │ ┌─────┼─────┐ │ │ │ │ │ │ │ Button PIR Sensor Program LED Relay Motor │ │ │ │ │ │ │ └───┴────┴──────────────┴─────────────┴─────┴─────┘

And the GPIO pins are the electrical communication points between the ESP32 and the outside world.

In one sentence:

GPIO pins allow the ESP32 to interact with the physical world by reading inputs, producing outputs, and connecting to peripherals such as sensors, displays, communication modules, and actuators.

Keep learning. Keep building. Keep growing.

© 2026 Ugenz Academy