ESP32 GPIO pins: a practical guide
GPIO is General-Purpose Input/Output. Each pin can be a digital output or a digital input. A pin can also connect to a built-in peripheral (ADC, DAC, PWM, touch, UART, I²C, SPI…). The notes below are for the classic ESP32-WROOM-32 DevKit. The S2, S3, C3 and C6 variants use different pin maps.

Photo: Ubahnverleih, CC0
| GPIO | Status | Features | Notes |
|---|
LED resistor calculator
- Exact R
- 140 Ω
- Use (E12)
- 150 Ω
- Actual current
- 9.3 mA
- Resistor power
- 13 mW
R = (Vsupply − VLED) / I. Round up to the next standard value. Then the current stays at or below your target.
Digital output
- Use
pinMode(pin, OUTPUT), thendigitalWrite(pin, HIGH)to set the pin to 3.3 V.LOWsets the pin to 0 V. - “Source” current: GPIO → resistor → LED → GND (HIGH = on).
- “Sink” current: 3.3 V → resistor → LED → GPIO (LOW = on).
Current limits
- Keep the current of each pin at ≤ 20 mA. The absolute maximum is about 40 mA. At this maximum, the life of the chip becomes shorter.
- Do not connect motors, relays, buzzers or LED strips directly to a pin. Use a logic-level MOSFET or a motor driver. For coils, also use a flyback diode. Refer to DC motors.
- You can adjust the drive strength in software (levels of about 5/10/20/40 mA).
3.3 V logic levels
- Do not connect a 5 V signal directly to a pin. ESP32 pins are not 5 V tolerant. For a 5 V sensor output, use a voltage divider or a level shifter.
- The pin reads HIGH at more than about 2.5 V (0.75 × VDD). The pin reads LOW at less than about 0.8 V (0.25 × VDD).
Digital input & pull-ups
- An input that has no connection “floats” and reads random values.
INPUT_PULLUP/INPUT_PULLDOWNenable internal resistors of about 45 kΩ.- GPIO 34–39 are input-only and have no internal pull resistors. Add external resistors.
- Mechanical buttons bounce. Debounce them in software (about 20–50 ms).
Analog input (ADC)
- The ADC is 12-bit:
analogRead()gives 0–4095. To hear what this means, go to the Quantization page. - The response is not linear near 0 V. At more than about 3.1 V, the readings stay flat. For calibrated readings, use
analogReadMilliVolts(). - ADC2 pins do not operate when Wi-Fi is on. Use ADC1 (GPIO 32–39) when possible.
Analog output
- GPIO 25 and 26 have a true 8-bit DAC. Use
dacWrite(pin, 0–255). - All other output pins can make an output that is almost analog with PWM:
ledcAttach()+ledcWrite()(16 channels, up to 20-bit resolution on the original ESP32).
Boot / strapping pins
- At reset, the chip reads GPIO 0, 2, 5, 12 and 15 to select the boot mode.
- A circuit that pulls these pins to the “incorrect” level can stop the board. Then the board cannot boot or flash.
- If GPIO 12 is HIGH at boot, the chip selects 1.8 V flash. Then many boards do not start.
Interrupts & touch
attachInterrupt(pin, isr, RISING)operates on all GPIO pins. Keep the ISR short and mark itIRAM_ATTR.- There are ten capacitive touch pins (T0–T9). When you touch the pin,
touchRead(pin)gives a lower value.
Powering the board
- USB supplies 5 V. The on-board regulator makes the 3.3 V that the chip needs.
- The 3V3 pin can supply a few hundred mA to sensors. Do not connect motors or LED strips to the 3V3 pin.
- Wi-Fi transmit bursts use ~250–400 mA. A weak supply causes “brownout” resets.
- For more data, refer to the Power supplies page.
Switch large loads
- A GPIO pin supplies a control signal. It can supply only about 20 mA.
- To control 12 V strips, solenoids or motors, connect the pin to a MOSFET gate or a driver board (H-bridge, stepper driver, ESC).
- Always connect the grounds of the two supplies together.
Communication buses
HSPI & VSPI
- The ESP32 has four SPI controllers. SPI0 and SPI1 control the internal flash (GPIO 6–11). Two controllers stay available for your projects: HSPI (SPI2) and VSPI (SPI3).
- The names are historical. The two buses operate in the same way. Each bus has its own hardware, so the two buses can operate at the same time.
- VSPI is Arduino's default
SPIobject: SCK 18, MISO 19, MOSI 23, CS 5. - HSPI uses SCK 14, MISO 12, MOSI 13, CS 15. Make it with
SPIClass hspi(HSPI); hspi.begin();. Some of its pins are strapping pins. Make sure that GPIO 12 is LOW at boot. - One bus can operate with many devices. The devices share SCK/MOSI/MISO, and each device has its own CS pin. Use the second bus only if a device needs a different speed or mode. Also use it if you want to keep the data on a separate bus.
- On their default pins, the buses operate at up to 80 MHz. You can move the buses to other pins through the GPIO matrix with
SPI.begin(sck, miso, mosi, cs). Then the maximum speed is about 40 MHz.