PinoutSearch

Capacitive Touch Switch (TTP223 + Arduino)

Toggle an LED by touching a sensor pad — a button with no moving parts. Learn edge detection and toggling.

Beginner15 min

What you need

Wiring

Hover a pin or a wire to trace the connection.

Code

touch_switch.ino
// Toggle an LED each time the touch pad is tapped.
const int touchPin = 2;
const int ledPin   = 13;
bool ledOn = false;

void setup() {
  pinMode(touchPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  if (digitalRead(touchPin) == HIGH) { // touched
    ledOn = !ledOn;
    digitalWrite(ledPin, ledOn);
    delay(300);                          // simple debounce
  }
}

Steps

  1. Wire the touch sensor: VCC to 5V, GND to GND, SIG to D2.
  2. Wire the LED on D13 through a 220Ω resistor to GND.
  3. Upload — each tap toggles the LED on or off.
  4. It even works through thin plastic, so you can hide the pad behind a panel.