TTP223 touch inputs and edge detection
Toggle once per touch and distinguish momentary output from hardware toggle mode.
Goal: build a touch input that changes an LED state once when a new touch begins. Use the Touch-Controlled LED project for the complete circuit, sketch and linked parts list.
A capacitive touch module senses a change near its pad and produces a digital output. Common TTP223 modules offer momentary or toggle output, and active-HIGH or active-LOW behaviour, selected by board solder bridges. Confirm the PCB instructions for your exact module; bridge labels are not universal.
For the project, choose momentary, active-HIGH output. OUT should be LOW at rest and HIGH while touched. With power disconnected, connect VCC to UNO 5V, GND to GND and OUT to D2. Leave the pad untouched during startup so its baseline can settle. Keep long loose wires and nearby conductive objects away from the pad during your first test.
Reading HIGH inside loop() and toggling the LED every time will make it switch repeatedly while a finger is held down. Instead, remember the previous stable state and toggle only when the state changes from not touched to touched. This is edge detection. A release prepares the input for the next touch.
The project requires a stable value for 30ms before accepting a change. This filters brief fluctuations; it does not solve all interference or module configuration problems. Mechanical buttons need debounce too, but their contact bounce is a different physical effect.
Test four cases: a brief tap, a long hold, a release and second tap, and a finger already on the pad at startup. A long hold should trigger only once. If it takes two taps to change the LED, check that the module itself is not already configured to toggle.
For use with an ESP32, choose a supply and output level compatible with 3.3V GPIO. Do not assume a module powered from 5V produces a safe signal for a 3.3V input.
Reference for edge detection: https://docs.arduino.cc/built-in-examples/digital/StateChangeDetection/