Pack of 10 Γ TTP223 capacitive touch switch modules with self-locking (latch) behaviour. Perfect for touch-controlled lighting panels, dimmers, smart-home panels and ESP32/Arduino projects.
10PCS TTP223 Capacitive Touch Switch Self Locking Button Module ESP32
Simple wiring showing one touch module controlling a MOSFET-driven LED strip via ESP32 PWM. For mains lighting use a proper dimmable driver and qualified wiring.
Paste the following into an ESPHome device YAML (ESP32). This example uses a touch module on GPIO14 and a PWM output on GPIO16 to drive a MOSFET / LED driver. It implements short/long press logic: short press toggles light; long press ramps brightness while held.
esphome:
name: touch_dimmer
platform: ESP32
board: esp32dev
wifi:
ssid: "YOUR_SSID"
password: "YOUR_PASSWORD"
logger:
api:
ota:
binary_sensor:
- platform: gpio
pin:
number: GPIO14
mode: INPUT
name: "Touch Button"
id: touch_btn
filters:
- delayed_on: 10ms
- delayed_off: 10ms
# PWM output as light
output:
- platform: ledc
pin: GPIO16
id: pwm_output
frequency: 1000 Hz
channel: 0
light:
- platform: monochromatic
name: "Touch Dimmer Light"
output: pwm_output
id: dimmer_light
default_transition_length: 0s
globals:
- id: press_start
type: unsigned long
restore_value: no
initial_value: '0'
- id: long_press_ms
type: int
restore_value: no
initial_value: '600' # ms threshold for long press
# Interval check to implement short vs long press behavior
interval:
- interval: 100ms
then:
- lambda: |-
bool pressed = id(touch_btn).state;
static bool was_pressed = false;
static bool long_mode = false;
static int ramp_dir = 1;
if (pressed && !was_pressed) {
id(press_start) = millis();
long_mode = false;
} else if (!pressed && was_pressed) {
unsigned long duration = millis() - id(press_start);
if (duration < id(long_press_ms)) {
// short press β toggle
if (id(dimmer_light).state) {
id(dimmer_light).turn_off();
} else {
id(dimmer_light).turn_on();
// ensure brightness at least 50% when turning on
id(dimmer_light).turn_on().set_level(0.5);
}
} else {
// released after long press β stop ramping
long_mode = false;
}
}
// if held long enough, enter ramp mode
if (pressed && (millis() - id(press_start) > id(long_press_ms))) {
long_mode = true;
}
// ramp logic when in long_mode and light is ON
if (long_mode && id(dimmer_light).state) {
float lvl = id(dimmer_light).current_values.get_brightness(); // 0..1
// direction alternates at endpoints
if (lvl >= 0.98) ramp_dir = -1;
if (lvl <= 0.02) ramp_dir = 1;
lvl += ramp_dir * 0.01; // step
if (lvl < 0) lvl = 0;
if (lvl > 1) lvl = 1;
id(dimmer_light).turn_on().set_level(lvl);
}
was_pressed = pressed;
Notes:
- Adjust long_press_ms and ramp speed to taste.
- This YAML requires ESPHome release with ledc LEDC output (ESP32). For ESP8266 adapt to pwm output.
Below are two practical ways to integrate touch buttons with WLED:
light.touch_dimmer_light.
- Create automations or use a direct script to call the WLED light (via light.turn_on with brightness) whenever the ESPHome dimmer changes level or when long-press ramp events occur.
- Advantages: reliable, uses Home Assistant service calls (no custom HTTP code).
http_request component (ESPHome) to POST JSON to http://WLED_IP/json/state to set "on":true and "bri":N where N is 0β255.# (Pseudo-example) Use ESPHome http_request to set WLED brightness
# Replace WLED_IP and port as needed. See WLED docs for exact endpoint details.
http_request:
useragent: esphome-touchdimmer
# In automations: call a lambda to run an http_request.post with JSON payload:
# {"on":true,"bri":128}
- Note: exact HTTP endpoint and JSON schema depend on WLED version; prefer Home Assistant bridge for simplicity unless you are familiar with WLED API.
If you run a custom FastLED sketch on the ESP32 (no WLED), the ESPHome dimmer approach can be adapted: read the TTP223 input and implement short/long press logic in your sketch to call FastLED.setBrightness() or update PWM output.
Compact, reliable touch buttons β excellent value for building modern touch panels and smart-lighting interfaces.