ESP32 Touch Pins: Capacitive Touch Sensor Guide

The ESP32 features a built-in capacitive touch sensor system with 10 touch channels (T0–T9) that can detect changes in capacitance when a finger touches or approaches a touch pad. This allows you to replace physical buttons with touch-sensitive surfaces at zero extra component cost.

Key advantage: The ESP32 touch sensors can wake the chip from Deep Sleep, making them ideal for battery-powered touch-activated devices.

ESP32 Touch Pin Mapping

Each touch channel is mapped to a specific GPIO pin. Not all GPIOs support touch sensing:

Touch ChannelGPIO PinStatus
T0GPIO4Available
T1GPIO0Strapping (Boot must be HIGH)
T2GPIO2Strapping (Boot must be LOW)
T3GPIO15Strapping (Boot must be HIGH)
T4GPIO13Available
T5GPIO12Strapping (JTAG + flash voltage)
T6GPIO14Available
T7GPIO27Available
T8GPIO33Available
T9GPIO32Available
⚠️ Strapping pin warning: T1 (GPIO0), T2 (GPIO2), T3 (GPIO15), and T5 (GPIO12) are strapping pins. Their state at boot determines the ESP32's boot mode. If using these as touch inputs, ensure they are not pulled HIGH or LOW incorrectly during power-up.

How Touch Sensing Works

The ESP32 touch sensor measures the charge/discharge cycle time of an RC circuit formed by the pin's parasitic capacitance. When a finger touches the pad, the capacitance increases, and the measured value changes:

  • Baseline (no touch): Typically 40–60 (low cycle count = low capacitance)
  • Touch detected: Value increases to 70–100+ (varies by pad size, wire length, and ambient conditions)
  • Threshold: Set midway between baseline and touch values (e.g., baseline + 20)

Basic Touch Read Example

// ESP32 Touch Read Example
// Connect a wire or copper pad to GPIO4 (T0)

#define TOUCH_PIN T0  // GPIO4
int threshold = 30;   // Adjust based on your setup

void setup() {
    Serial.begin(115200);
    delay(1000);
    Serial.println("ESP32 Touch Test - Touch GPIO4");
}

void loop() {
    int touchValue = touchRead(TOUCH_PIN);
    Serial.print("Touch value: ");
    Serial.println(touchValue);

    if (touchValue < threshold) {
        Serial.println("-> TOUCH DETECTED");
    }

    delay(200);
}

Calibrating Touch Thresholds

Touch readings vary significantly based on your physical setup. Follow this calibration routine:

  1. Measure baseline: Run the example above and note the value when not touching (e.g., 45)
  2. Measure touch: Touch the pad and note the peak value (e.g., 80)
  3. Set threshold: Use the midpoint: threshold = (baseline + touch) / 2
  4. Add hysteresis: Use separate on/off thresholds 5–10 apart to prevent flickering
Pro tip: Use larger touch pads (1–2 cm² copper) for more reliable detection. Longer wires to the pad act as antennas and increase noise — keep them under 15 cm.

Touch Interrupts (No Polling Required)

Instead of polling touchRead() in a loop, configure a touch interrupt that fires when the threshold is crossed:

// ESP32 Touch Interrupt - Fires when touch is detected

#define TOUCH_PIN T0
int threshold = 30;

void setup() {
    Serial.begin(115200);
    touchAttachInterrupt(TOUCH_PIN, onTouch, threshold);
    Serial.println("Touch interrupt configured. Touch GPIO4.");
}

void loop() {
    // CPU is free - interrupt handles touch detection
    delay(1000);
}

void onTouch() {
    Serial.println("TOUCH DETECTED via interrupt!");
}

Wake from Deep Sleep on Touch

One of the most powerful features: wake the ESP32 from Deep Sleep when a touch pad is touched:

// ESP32 Deep Sleep Wake via Touch Sensor

#define TOUCH_PIN T0  // GPIO4
int threshold = 30;

void setup() {
    Serial.begin(115200);
    delay(100);

    // Configure touch as wake-up source
    touchSleepWakeUpEnable(TOUCH_PIN, threshold);
    esp_sleep_enable_touch_wakeup();

    Serial.println("Entering Deep Sleep. Touch GPIO4 to wake.");
    esp_deep_sleep_start();
}

void loop() {
    // Never reached
}
Deep Sleep current: ESP32 draws ~5–10 µA in Deep Sleep. Touch wake-up adds ~1–5 µA depending on configuration. A 2000 mAh battery could last years in this mode.

Touch Sensor Limitations

IssueMitigation
Noise from power supplyUse a clean 3.3V regulator; avoid shared supply lines
Long wires (>15 cm)Keep sensor wire short; use shielded cable if necessary
Water/humidityApply conformal coating; recalibrate baseline periodically
Plastic enclosureThin plastic (under 3 mm) works; thicker reduces sensitivity
Temperature driftRe-calibrate baseline periodically (e.g., every 60 seconds)
Multiple adjacent padsSpace pads >10 mm apart; use guard traces

Touch Sensor Applications

  • Touch buttons — Replace mechanical buttons in waterproof designs
  • Proximity detection — Detect a hand approaching (before contact)
  • Touch slider / wheel — Use multiple adjacent pads with interpolation
  • Wake-on-touch — Battery-powered devices that activate on touch
  • Smart lamp controls — Dimmer, color change via touch
  • Security touchpads — Simple lock/unlock with a sequence

🔧 Check Touch Pin Compatibility

Our interactive pinout tool shows which GPIOs support touch and flags strapping pin conflicts.

Open Interactive Pinout

Related Guides