Skip to content

Example 36: Touch Sensor ​

Experiment Overview ​

ESP32 has built-in capacitive touch sensors supporting 10 touch pins (Touch0~Touch9), enabling touch detection without external components. FastBee provides the GPIO_TOUCH peripheral type (type: 21) for direct support.

Hardware Wiring ​

Touch ChannelGPIO PinDescription
Touch0GPIO4Touch input 0
Touch2GPIO2Touch input 2
Touch3GPIO15Touch input 3
Touch4GPIO13Touch input 4
Touch5GPIO12Touch input 5
Touch6GPIO14Touch input 6
Touch7GPIO27Touch input 7
Touch8GPIO33Touch input 8
Touch9GPIO32Touch input 9

Touch pins can detect touch by connecting directly to a metal pad or conductive material.

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "touch_01",
      "name": "Touch Input",
      "type": 21,
      "enabled": false,
      "pins": [4],
      "params": {}
    }
  ]
}

Peripheral Execution Linkage ​

Scenario: Touch Toggle Light (Polling Trigger) ​

Feature: Toggle LED on/off when touch sensor is touched

Web UI Configuration Steps ​

Step 1: Ensure LED Peripheral is Configured

  • Peripheral ID: led_d1
  • Type: GPIO Output

Step 2: Create Rule

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: Touch Toggle Light
    • Report Data: ✅ Enabled
    • Enable: ✅ Enabled

Step 3: Configure Trigger (Polling Trigger)

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Polling TriggerPeriodic condition check
    Target PeripheralSelect touch_01Touch sensor
    Polling Interval100100ms
    Condition Expressionvalue < 40Touch threshold

Step 4: Configure Action

  1. Click Add Action button

  2. Fill in:

    • Action Type: Select Toggle Level
    • Target Peripheral: Select led_d1
  3. Click Save button

ESP32 Touch Pin List ​

Touch ChannelGPIO PinTouch ChannelGPIO Pin
Touch0GPIO4Touch5GPIO12
Touch2GPIO2Touch6GPIO14
Touch3GPIO15Touch7GPIO27
Touch4GPIO13Touch8GPIO33
Touch9GPIO32

⚠️ Note: Touch1 (GPIO0) is not recommended; it may affect touch readings when WiFi is active

Notes ​

  1. Threshold: Value decreases when touched (typically <40); higher when not touched (>60); determine threshold through actual testing
  2. Wire Length: Wire from touch pin to sensing pad should not be too long (<30cm)
  3. ESP32-S3: S3 has improved touch sensors with different threshold ranges
  4. Anti-False-Touch: Add touch confirmation delay to avoid false triggers
  5. WiFi Impact: WiFi operation may slightly affect touch readings

FastBee | fastbee.cn