The TTP223 is a tiny capacitive touch sensor — the small square board with a round pad that costs about ₹15. Touch the pad, or the plastic in front of it, and its output goes HIGH. It replaces a push button where you want a sealed, splash-proof panel, which is handy in kitchens and bathrooms.
On the Uno it runs from 5V and its I/O pin goes straight to D2. The chip drives its own output, so it needs no pull-up resistor and doesn’t bounce like a mechanical button.
The sketch tells a tap (which toggles the on-board LED) from a long press of one second — two actions from one pad.
Wiring
| Arduino Uno R3 | TTP223 capacitive touch module | Wire | Notes |
|---|---|---|---|
| 5V | VCC | red | Works from 2 to 5.5 V; at 5 V its output is a full 5 V HIGH. |
| D2 | I/O | yellow | HIGH while touched (default pads). Printed SIG or OUT on some boards. |
| GND | GND | black |
2.0–5.5 V part, 5 V board. I/O drives to the supply voltage, so power it from 3.3 V on ESP32 and Pico and from 5 V on Uno. It runs happily at either.
Board quirks
- The chip calibrates itself in the first half second after power-up. A finger on the pad during that time becomes the new “untouched” level and the pad stops working until the next power cycle.
- Solder pad A makes the output active-LOW; pad B makes it toggle on each touch. With pad A bridged, change the sketch to look for
LOW. - It senses through 1–3 mm of plastic or glass, so you can hide it behind an enclosure wall with no hole. Stick it flat and tight — an air gap kills the sensitivity.
- No pull-up is needed: the TTP223 drives its output actively, both HIGH and LOW.
Code
// TTP223 capacitive touch module on an Arduino Uno R3.
// VCC → 5V, I/O → D2, GND → GND. Default pads: I/O is HIGH while touched.
// Tap = toggle the on-board "L" LED, hold 1 s = long press.
const uint8_t TOUCH_PIN = 2;
bool ledOn = false;
bool lastTouch = false;
bool longSent = false;
unsigned long touchStart = 0;
void setup() {
pinMode(TOUCH_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
Serial.println(F("TTP223 on D2 - tap or hold (don't touch it during power-up)"));
}
void loop() {
bool touch = digitalRead(TOUCH_PIN) == HIGH;
if (touch && !lastTouch) {
touchStart = millis();
longSent = false;
}
if (touch && !longSent && millis() - touchStart > 1000) {
longSent = true;
Serial.println(F("Long press"));
}
if (!touch && lastTouch && !longSent) {
ledOn = !ledOn;
digitalWrite(LED_BUILTIN, ledOn);
Serial.println(ledOn ? F("Tap - LED on") : F("Tap - LED off"));
}
lastTouch = touch;
delay(10);
}// TTP223 capacitive touch module on an Arduino Uno R3.
// VCC → 5V, I/O → D2, GND → GND. Default pads: I/O is HIGH while touched.
// Tap = toggle the on-board "L" LED, hold 1 s = long press.
const uint8_t TOUCH_PIN = 2;
bool ledOn = false;
bool lastTouch = false;
bool longSent = false;
unsigned long touchStart = 0;
void setup() {
pinMode(TOUCH_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
Serial.println(F("TTP223 on D2 - tap or hold (don't touch it during power-up)"));
}
void loop() {
bool touch = digitalRead(TOUCH_PIN) == HIGH;
if (touch && !lastTouch) {
touchStart = millis();
longSent = false;
}
if (touch && !longSent && millis() - touchStart > 1000) {
longSent = true;
Serial.println(F("Long press"));
}
if (!touch && lastTouch && !longSent) {
ledOn = !ledOn;
digitalWrite(LED_BUILTIN, ledOn);
Serial.println(ledOn ? F("Tap - LED on") : F("Tap - LED off"));
}
lastTouch = touch;
delay(10);
}Expected serial output
TTP223 on D2 - tap or hold (don't touch it during power-up)
Tap - LED on
Tap - LED off
Long pressTTP223 on D2 - tap or hold (don't touch it during power-up) Tap - LED on Tap - LED off Long press
Common errors
Doesn’t respond to touch at all
It calibrated with your finger on it, or something metal sits near the pad. Power-cycle the Uno with nothing touching the sensor.
Triggers by itself
Long wires to the module or a noisy phone charger. Keep the wires short and use a clean 5 V supply; a ground plane under the pad also helps.
Each touch toggles the output instead of following my finger
Pad B is bridged (toggle mode). Remove the solder blob, or keep it and treat each change as a press.