ESP32 I2C Pins: Complete Communication Guide

The ESP32 has 2 I2C bus interfaces that can operate in both master and slave mode. Like other ESP32 peripherals, I2C pins are fully remappable — you can assign SDA and SCL to almost any GPIO pin using the Wire library.

Default ESP32 I2C Pins

In the Arduino IDE, the default I2C pins are:

FunctionDefault PinArduino Constant
SDA (Data)GPIO21SDA (21)
SCL (Clock)GPIO22SCL (22)

These defaults are used by many popular ESP32 libraries (Adafruit, SSD1306 OLED, BME280, etc.) and are the safest choice for I2C communication.

Using I2C on ESP32 with Arduino

// ESP32 I2C Scanner - Find connected I2C devices
#include <Wire.h>

void setup() {
    Serial.begin(115200);
    Wire.begin();  // Default: SDA=GPIO21, SCL=GPIO22
    Serial.println("I2C Scanner");
}

void loop() {
    byte error, address;
    int deviceCount = 0;
    
    for (address = 1; address < 127; address++) {
        Wire.beginTransmission(address);
        error = Wire.endTransmission();
        if (error == 0) {
            Serial.print("Found device at 0x");
            Serial.println(address, HEX);
            deviceCount++;
        }
    }
    Serial.print("Total: "); Serial.print(deviceCount);
    Serial.println(" device(s)");
    delay(2000);
}

Remapping I2C to Custom Pins

You can assign I2C to any GPIO using Wire.begin(SDA, SCL):

// Remap I2C to custom pins
#include <Wire.h>

#define CUSTOM_SDA 13
#define CUSTOM_SCL 14

void setup() {
    Wire.begin(CUSTOM_SDA, CUSTOM_SCL);
    // Now I2C operates on GPIO13 (SDA) and GPIO14 (SCL)
}

Using Both I2C Buses

ESP32 has two I2C buses accessible via Wire and Wire1:

// Dual I2C Bus Example
#include <Wire.h>

void setup() {
    Wire.begin();           // Bus 0: GPIO21 (SDA), GPIO22 (SCL)
    Wire1.begin(33, 32);    // Bus 1: GPIO33 (SDA), GPIO32 (SCL)
    
    // Scan both buses
    Wire.beginTransmission(0x3C);  // OLED on Bus 0
    Wire1.beginTransmission(0x76); // BME280 on Bus 1
}

I2C Speed and Configuration

ParameterValue
Standard mode100 kHz
Fast mode400 kHz (default on ESP32)
Fast mode plus1 MHz (set via Wire.setClock(1000000))
Maximum devices per bus~100 (limited by capacitance, not ESP32)

I2C Best Practices

  • Use GPIO21/GPIO22 for I2C unless you have a specific reason to remap
  • Add 4.7kΩ pull-up resistors on SDA and SCL lines (some breakout boards include these)
  • Keep wires short (under 50cm) for reliable communication at 400 kHz
  • Use level shifters if connecting 5V I2C devices to the 3.3V ESP32
  • Check for address conflicts using the I2C scanner code above

🔧 Check I2C Pin Compatibility

Our interactive pinout shows which pins are safe for I2C remapping and checks for conflicts with other peripherals.

Open Interactive Pinout

Related Guides