主要内容

ESP32 Touch Sense

Read state of capacitive touch pins on Arduino-compatible ESP32 board

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 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 10-channel capacitive touch sensor module. This module detects 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 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 Board VariantAvailable Capacitive Touch GPIO PinsDescription
ESP32-WROOM-DevKitV1 (30 pin)Touch 0: GPIO 4On this board variant, you can use only 9 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)

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

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.

  • Logical 0 — Indicates the board pin is touched.

  • Logical 1 — Indicates the board pin is untouched.

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 Output.

Data Types: uint16

Parameters

expand all

Enter the GPIO pin on the Arduino-compatible ESP32 board to be used as the capacitive touch input. Click View pin map to see all the GPIO pins. For more information on allocated pins for the block, see Pin Mapping for Arduino Timer-Independent Blocks.

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.

Set the time duration in clock cycles for capacitance measurement to control sensitivity and accuracy of touch. Higher values enhance sensitivity but also reduce response times.

Set the interval in clock cycles between each capacitance measurement. Higher values lower power consumption but also reduce response times.

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.

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

Version History

Introduced in R2026a