Blog
ESP32 Touch Pins
Ten capacitive touch inputs, no moving parts, works through plastic — the ESP32 touch sensor is the cheapest invisible button you will ever wire. Here is how to use it without fighting it.
How to Use Touch Pins on ESP32?
Read the pin with touchRead() and compare against a threshold — on classic ESP32 the value drops when touched. A minimal touch button is three lines:
int v = touchRead(T4);
if (v < 300) { /* touched */ }
That is the whole API. The first run surprises everyone: the raw value differs on every pin and board, so hardcode nothing — calibrate at boot.
How to Use Multiple Touch Pins on ESP32?
All ten touch pins work simultaneously, each with its own threshold. Read them one at a time in loop() — touchRead is fast enough that ten reads per cycle is nothing. For event-driven code, call touchAttachInterrupt(pin, callback, threshold) once per pin in setup(). The gotcha: adjacent pads interact, so keep them a few centimeters apart and calibrate each pad separately.
Which Pins Are Touch Pins?
Ten of them on classic ESP32: T0-T9 on GPIO 4, 0, 2, 15, 13, 12, 14, 27, 33, and 32. GPIO 0 and 2 are also strapping pins, so a touch pad there can occasionally interfere with boot. The ESP32-S2 and S3 expose 14 touch pins on different numbers entirely — check your board's pinout.
What Does touchRead() Actually Return?
A raw capacitance counter, roughly 0-1023, that falls when the pad is touched on classic ESP32 — lower value means finger present. On some newer chips the direction flips, so test yours first. Do not compare values across pins; they are only meaningful against that pin's own baseline.
How Do I Choose a Good Threshold?
Measure the baseline at boot — average ten touchRead() samples with nothing near the pad — then set the threshold to baseline minus 60-100. Recalibrate whenever wiring changes: a longer wire raises the baseline, humidity drifts it. A boot-time baseline is non-negotiable; sliding calibration in loop() is overkill for most projects.
Do Touch Pins Work in Deep Sleep?
Yes — this is the classic use case: esp_sleep_enable_touchpad_wakeup() and the chip wakes when the pad is touched, drawing near nothing until then. The touch subsystem runs off RTC hardware, so it keeps sensing while the CPU sleeps. The power and deep-sleep FAQ covers the wiring end to end.
Can Touch Pins Be Used as Normal GPIO?
Yes — they are ordinary GPIOs first, and touch sensing is extra hardware on top. Use them for digital I/O or ADC like any other pin; the only difference is you can also ask how capacitive they feel. No configuration needed. Just do not touch them.
Why Is My Touch Read Unstable?
Wires are antennas, and the touch circuit is sensitive enough to notice. Keep leads under ~10cm, avoid AC mains and the WiFi antenna, and put a ground plane under the pad. I had a 30cm jumper false-triggering every second near a wall outlet — shortened to 8cm and it went silent for a year. If it still drifts, the debugging FAQ has the diagnosis order.
Does Touch Work Through Glass or Plastic?
Yes — capacitive sensing goes through a few millimeters of non-conductive material. I have run touch buttons through 3mm acrylic for months without a false trigger. Metal foil kills it, and water changes the baseline — a wet finger reads as a permanent touch until it dries.
How Do I Test Touch Logic Before Hardware?
Prototype the surrounding logic at app.sensbench.com — threshold state machines, multi-pad handling, wake flows — then flash to hardware for final calibration. The capacitive part only exists on real silicon, but the state machine around it is where bugs live anyway.