ESP32Cube Logo
Sign In
ESP32 Touch Button

ESP32 Touch Button

esp32cube
May 23, 2026
Tutorial
1202 views

This article discusses creating a touch-sensitive button using the ESP32's internal capacitive touch sensors. It details the GPIO pins associated with the sensors and explains how to read touch inputs using Arduino syntax.

LEDMotorSensor

In this article we will talk about how to create a touch-sensitive button with ESP32's internal capacitive touch sensors:

touch_button1.png

ESP32 touch buttons can be used to control a variety of devices, such as LEDs, motors, and speakers. They can also be used to create user interfaces, such as menus and forms.

ESP32 features 10 internal capacitive touch sensors that can be utilized to create touch-sensitive buttons. The following are the GPIO pins corresponding to these sensors:

  • T0: GPIO 4
  • T1: GPIO 0
  • T2: GPIO 2
  • T3: GPIO 15
  • T4: GPIO 13
  • T5: GPIO 12
  • T6: GPIO 14
  • T7: GPIO 27
  • T8: GPIO 33
  • T9: GPIO 32

Arduino also provides corresponding syntax: _touchRead(Touch Pin *);_

For instance, to read the touch sensor 0 (T0), you can perform: int value = touchRead(4);

The values read here are analog, and you can use the Serial Monitor to check the sensor readings and adjust the code accordingly. Here is the corresponding code:

/*******************************************************
   ESP32 Touch Button
   Function: Change LED state with a single touch on a touch button
   Pin: T0 (GPIO4)
   T0: GPIO 4
   T2: GPIO 2
   T3: GPIO 15
   T4: GPIO 13
   T5: GPIO 12
   T6: GPIO 14
   T7: GPIO 27
   T8: GPIO 33
   T9: GPIO 32
*******************************************************/

#define TOUTCH_PIN 4 // ESP32 Pin D4
#define LED_PIN 2

int touch_value = 100;
int flg = 0;

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("ESP32 Touch Test");
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
}

void loop() {
  touch_value = touchRead(TOUTCH_PIN);
  Serial.println(touch_value);
  if (touch_value < 40) {
    flg = ~flg;
    digitalWrite(LED_PIN, flg);
  }
}

Here's the experimental result:

touch_button2.jpg

And just like that, a simple touch-sensitive button is complete.

Share this article

Comments

0

Please sign in to post a comment.

No comments yet.

Related Articles

ESP32 Arduino Button Input: Practical Guide and Debouncing

Tutorial·228 views

ESP32 + WS2812B LED Strip + 18650 Battery: Rechargeable RGB Lighting Device

Tutorial·299 views

ESP32 LED Chaser (Running Light) Experiment

Tutorial·162 views

Control GPIO Output: Light Up an LED on ESP32

Tutorial·149 views

ESP32Cube Development Guide

Tutorial·177 views
View more in this category→
Copyright © 2026 ESP32Cube. All rights reserved.•1.0.1•Terms·Privacy
Source codeTwitterDiscord