Example 36: Touch Sensor
About 1 min
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 Channel | GPIO Pin | Description |
|---|---|---|
| Touch0 | GPIO4 | Touch input 0 |
| Touch2 | GPIO2 | Touch input 2 |
| Touch3 | GPIO15 | Touch input 3 |
| Touch4 | GPIO13 | Touch input 4 |
| Touch5 | GPIO12 | Touch input 5 |
| Touch6 | GPIO14 | Touch input 6 |
| Touch7 | GPIO27 | Touch input 7 |
| Touch8 | GPIO33 | Touch input 8 |
| Touch9 | GPIO32 | Touch input 9 |
Touch pins can detect touch by connecting directly to a metal pad or conductive material.
JSON Configuration Example
{
"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
- Click Peripheral Config in the left menu → Switch to Peripheral Execution tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
Touch Toggle Light - Report Data: ✅ Enabled
- Enable: ✅ Enabled
- Rule Name:
Step 3: Configure Trigger (Polling Trigger)
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Polling Trigger Periodic condition check Target Peripheral Select touch_01Touch sensor Polling Interval 100100ms Condition Expression value < 40Touch threshold
Step 4: Configure Action
Click Add Action button
Fill in:
- Action Type: Select Toggle Level
- Target Peripheral: Select
led_d1
Click Save button
ESP32 Touch Pin List
| Touch Channel | GPIO Pin | Touch Channel | GPIO Pin |
|---|---|---|---|
| Touch0 | GPIO4 | Touch5 | GPIO12 |
| Touch2 | GPIO2 | Touch6 | GPIO14 |
| Touch3 | GPIO15 | Touch7 | GPIO27 |
| Touch4 | GPIO13 | Touch8 | GPIO33 |
| Touch9 | GPIO32 |
⚠️ Note: Touch1 (GPIO0) is not recommended; it may affect touch readings when WiFi is active
Notes
- Threshold: Value decreases when touched (typically <40); higher when not touched (>60); determine threshold through actual testing
- Wire Length: Wire from touch pin to sensing pad should not be too long (<30cm)
- ESP32-S3: S3 has improved touch sensors with different threshold ranges
- Anti-False-Touch: Add touch confirmation delay to avoid false triggers
- WiFi Impact: WiFi operation may slightly affect touch readings
