Index

What is a Capacitive Touch Sensor?
Capacitive touch sensing is how your smartphone screen works — it detects the electrical changes from your skin when you touch it. The ESP32 has built-in capacitive touch sensing on certain GPIO pins, which means:
You can detect touch input using just a wire or a piece of foil — no external module needed.
Which ESP32 Pins Support Touch?
Here’s a list of GPIO pins on the ESP32 that support capacitive touch:
GPIO | Touch Pad Name | Arduino IDE Name |
---|---|---|
4 | T0 | T0 |
0 | T1 | T1 |
2 | T2 | T2 |
15 | T3 | T3 |
13 | T4 | T4 |
12 | T5 | T5 |
14 | T6 | T6 |
27 | T7 | T7 |
33 | T8 | T8 |
32 | T9 | T9 |
Not all ESP32 boards expose all these pins. Double-check your board’s pinout.
What You Need
- ESP32 Dev Module
- Jumper wire / copper tape / foil (as a touchpad)
- Arduino IDE installed
- USB cable
Wiring (Optional)
Just connect a jumper wire to one of the touch GPIOs (say GPIO 4), and leave the other end exposed for touching. You can tape foil to the end to make it more touch-sensitive.
Arduino Code
#define TOUCH_PIN T0 // GPIO 4
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Touch Sensor Test");
}
void loop() {
int touchValue = touchRead(TOUCH_PIN);
Serial.println(touchValue);
delay(200);
}
touchRead()
returns a value based on capacitance — lower values mean it’s being touched!
What to Expect
- Without touch: values like 70–100 (varies by pin and environment)
- When touched: value drops sharply, maybe to 20–30 or less
- You can set a threshold to trigger actions when touched
Add a Touch Threshold
#define TOUCH_THRESHOLD 40
void loop() {
int value = touchRead(TOUCH_PIN);
if (value < TOUCH_THRESHOLD) {
Serial.println("Touched!");
} else {
Serial.println("Not touched.");
}
delay(200);
}
Use Case Ideas
- DIY touch buttons (light switch, fan control)
- Hidden touchpad under plastic or wood
- Secret trigger for alarms
- Smart table with touch zones
- Simple gesture controls (multiple touch pins)
Tips & Gotchas
- Electromagnetic interference can affect readings — try shielding wires.
- Humidity and material type can affect sensitivity.
- Avoid using touch pins for other I/O simultaneously.
- Don’t forget some GPIOs like 0, 2, 15 have special boot functions.
Bonus: Serial Plotter Visualization
Use the Arduino IDE Serial Plotter to visualize the drop when you touch the wire — great for finding the perfect threshold value!
Conclusion
ESP32’s capacitive touch sensing is a powerful hidden gem — you can build slick, futuristic touch interfaces without spending a rupee on extra components. It’s fast, responsive, and really fun to experiment with!