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
1 comment
[…] Willst Du Touchsensoren bedienen, wähle ein Modul mit ESP32 Chip. Anwendungsbeispiele findest Du hier oder […]