Hauptinhalt

ESP32 Touch Sense

R2026b

Read state of capacitive touch pins on Arduino-compatible ESP32 and ESP32-S3 boards

Since R2026a

  • Arduino ESP32 Touch Sense

Libraries:
Simulink Support Package for Arduino Hardware / Common

Description

Use the ESP32 Touch Sense block to read the state of capacitive touch pins on Arduino®-compatible ESP32 and ESP32-S3 boards. The block outputs a logical 1 (high) value indicating a touch on the pin and a logical 0 (low) value when the pin is untouched. The block can also output a raw sensor value that represents the capacitance measured at the touch pin.

Supported ESP32 Boards and Available Capacitive Touch Pins

The Arduino-compatible ESP32 boards have a 10-channel capacitive touch sensor module. ESP32-S3 boards have a 14-channel capacitive touch sensor module. These modules detect finger contact or proximity by measuring changes in capacitance.

The ESP32 Touch Sense block reads the states of these capacitive touch-enabled GPIO pins on the Arduino-compatible ESP32 and ESP32-S3 boards. This table summarizes the ESP32 variant boards that the block supports, the number of accessible touch GPIO pins, and any associated limitations.

Supported Arduino-Compatible ESP32 and ESP32-S3 Board Variant(s)Available Capacitive Touch GPIO PinsDescription
ESP32-WROOM-DevKitV1 (30 pin)Touch 0: GPIO 4On this board variant, you can use only nine touch channels and GPIO 0 is not accessible.
Touch 2: GPIO 2
Touch 3: GPIO 15
Touch 4: GPIO 13
Touch 5: GPIO 12
Touch 6: GPIO 14
Touch 7: GPIO 27
Touch 8: GPIO 33
Touch 9: GPIO 32

ESP32-WROOM-DevKitV1 (36 pin)

ESP32-WROOM-DevKitC (38 pin)

ESP32-WROVER-Module

Touch 0: GPIO 4 On this board variant, you can use all 10 touch channels.
Touch 1: GPIO 0
Touch 2: GPIO 2
Touch 3: GPIO 15
Touch 4: GPIO 13
Touch 5: GPIO 12
Touch 6: GPIO 14
Touch 7: GPIO 27
Touch 8: GPIO 33
Touch 9: GPIO 32
ESP32-S3Touch 1: GPIO 1On this board variant, you can use all 14 touch channels.
Touch 2: GPIO 2
Touch 3: GPIO 3
Touch 4: GPIO 4
Touch 5: GPIO 5
Touch 6: GPIO 6
Touch 7: GPIO 7
Touch 8: GPIO 8
Touch 9: GPIO 9
Touch 10: GPIO 10
Touch 11: GPIO 11
Touch 12: GPIO 12
Touch 13: GPIO 13
Touch 14: GPIO 14

Note

GPIO 0 (touch channel 1) is available on ESP32 variant boards with 32 or more GPIO pins.

Examples

Ports

Output

expand all

The block outputs the state of the pin specified in the Touch pin parameter of the block.

For ESP32 WROOM and WROVER boards, a value of 0 indicates touched and 1 indicates not touched. Whereas, for ESP32-S3 board, a value of 1 indicates touched and 0 indicates not touched.

Data Types: Boolean

The block outputs a numeric value indicating the capacitance in Farads measured at the touch pin sensor of the Arduino board.

Dependencies

  • To enable this port, select Enable touch value.

  • The data type for the output touch value depends on the board variant. The data is uint16 for ESP32 and uint32 for ESP32-S3.

Data Types: uint16 | uint32

Parameters

expand all

Select the ESP32 board variant for the capacitive touch sense operation. The block supports ESP32 and ESP32-S3 variants. The selected variant determines the available touch pins, threshold range, and touch value output data type. ESP32 boards provide 10 touch channels (T0-T9) with a 16-bit threshold and touch value output while ESP32-S3 boards provide 14 touch channels (T1-T14) with a 32-bit threshold and touch value output.

Enter the GPIO pin on the ESP32 or ESP32-S3 board to be used as the capacitive touch input. Click View pin map to see all the GPIO pins.

Enter a threshold value for distinguishing between touched and untouched states on the Arduino pin. A lower threshold means a higher capacitive sensitivity and vice versa.

Select this parameter to enable the Touch value output port. This port outputs the raw capacitance value measured at the touch pin sensor of the Arduino board.

Set the time duration in milliseconds for capacitance measurement to control sensitivity and accuracy of touch. Higher values enhance sensitivity and lower power consumption, leading to a slower response. Lower values reduce sensitivity and increase power consumption for a faster response.

Set the interval in milliseconds between each capacitance measurement. Higher values enhance sensitivity and lower power consumption, leading to a slower response. Lower values reduce sensitivity and increase power consumption for a faster response.

Specify how often the block reads the state of the touch pin.

Version History

Introduced in R2026a

expand all