Home » ESP32 capacitive touch example

ESP32 capacitive touch example

by shedboy71

Another great feature of the ESP32 is that it has the ability to detect touch on various pins by having capacitive touch sensors, in fact the ESP32 has 10 of these

If you look at the pin mapping you will see the following – these are the pins that support touch

static const uint8_t T0 = 4;
static const uint8_t T1 = 0;
static const uint8_t T2 = 2;
static const uint8_t T3 = 15;
static const uint8_t T4 = 13;
static const uint8_t T5 = 12;
static const uint8_t T6 = 14;
static const uint8_t T7 = 27;
static const uint8_t T8 = 33;
static const uint8_t T9 = 32;

Its easy to read the touch sensors by using the function: touchRead(Touch Pin #);

We will create an example where when we touch a pin an led will light, you may need to adjust the value called touch_value

These could be used for touch buttons

Code

[cpp]

#define TOUCH_PIN T0 //connected to 4
#define LED_PIN A13 //connected to 15
int touch_value = 100;

void setup()
{
Serial.begin(9600);
Serial.println(“ESP32 Touch Test”);
pinMode(LED_PIN, OUTPUT);
digitalWrite (LED_PIN, LOW);
}

void loop()
{
touch_value = touchRead(TOUCH_PIN);
Serial.println(touch_value); // get value using T0
if (touch_value < 50)
{
digitalWrite (LED_PIN, HIGH);
}
else
{
digitalWrite (LED_PIN, LOW);
}
delay(1000);
}

[/cpp]

 

Demonstration

 

You may also like

1 comment

Welches ESP-Modul ist das Richtige? - ShopOfThings 17th August 2018 - 11:13 am

[…] Willst Du Touchsensoren bedienen, wähle ein Modul mit ESP32 Chip. Anwendungsbeispiele findest Du hier oder […]

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.