Example Code for Arduino-Capacitive Touch

Last revision 2026/02/05

This section introduces how to get and print the status of the touch sensor on FireBeetle 2 ESP32-E by Arduino code.

Hardware Preparation

Other Preparation Work

FireBeetle 2 ESP32-E provides the function of capacitive touch sensing with a total of 7 touch pins available, labeled as T0 to T6. The corresponding pin numbers are shown in the table below:

Touch Sensor Pin Number
T0 IO4/D12
T1 IO0/D5
T2 IO2/D9 (Connected to the on-board LED, and can't be used to test the touch sensing function)
T3 IO15/A4
T4 IO13/D7
T5 IO12/D13
T6 IO14/D6

PinMode setting is not required. The touchRead() returns a value within 0-255. The larger the touch intensity, the smaller the returned value. To obtain the GPIO status of the touch sensor, just need to call the touchRead function, whose function prototype is: uint16_t touchRead(uint8_t pin).

Sample Code

Burn the routine, use the pin IO4/D12 as a touch button, and return the touch value through the serial monitor.

void setup() {
  Serial.begin(115200);  
  Serial.println("FireBeetle Board-ESP32 Touch Test");
}

void loop() {
  Serial.println(touchRead(T0));  
  delay(100);
}

Result

The value returned decreases as the intensity of touch on pin IO4/D12 increases, with a value of 65 indicating no touch.

DFR0654-Capacitive touch result

Was this article helpful?

TOP