A TTP223 module turns any spot behind plastic into a button — popular for switch boards and lamp controls. On the S3 it is one digital pin: I/O to GPIO5, powered from 3V3.
The S3 also has capacitive touch built in, so the sketch reads a bare wire on GPIO2 alongside. Run it and you will see why the module still earns its ₹20: it needs no tuning.
Wiring
| ESP32-S3-DevKitC-1 | TTP223 capacitive touch module | Wire | Notes |
|---|---|---|---|
| 3V3 | VCC | red | At 3.3 V the I/O output is 3.3 V too. |
| 5 | I/O | yellow | |
| GND | GND | black |
2.0–5.5 V part, 3.3 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 S3 has 14 capacitive touch pins (GPIO1–14) of its own. A bare wire on GPIO2 works as a touch pad with no module — the sketch reads both so you can compare.
- On the S3,
touchRead()rises when touched. On the original ESP32 it falls, so thresholds copied from old tutorials never trigger here. - The TTP223 is better behind thick plastic or glass and with wet fingers; the built-in touch is free but needs tuning, and long wires make it noisy.
- Default TTP223 jumpers: momentary, output HIGH while touched. Bridge pad A for active-LOW, pad B for toggle mode.
Code
// TTP223 touch module on an ESP32-S3-DevKitC-1, compared with the S3's own touch sensor.
// TTP223: VCC → 3V3, GND → GND, I/O → GPIO5 (HIGH while touched, default jumpers).
// Built-in touch: a bare wire or a coin of foil on GPIO2 (TOUCH2) — no module needed.
// On the S3 the touchRead() value RISES when touched (on the original ESP32 it falls).
constexpr uint8_t TTP_PIN = 5;
constexpr uint8_t TOUCH_PIN = 2;
uint32_t baseline = 0;
void setup() {
Serial.begin(115200);
pinMode(TTP_PIN, INPUT);
delay(200);
for (int i = 0; i < 8; i++) baseline += touchRead(TOUCH_PIN);
baseline /= 8;
Serial.printf("TTP223 on GPIO5, bare touch pad on GPIO2 (baseline %lu)\n", (unsigned long)baseline);
}
void loop() {
bool ttp = digitalRead(TTP_PIN) == HIGH;
uint32_t raw = touchRead(TOUCH_PIN);
bool pad = raw > baseline + baseline / 10; // 10 % above the untouched value; tune for your pad
static bool lastTtp = false, lastPad = false;
if (ttp != lastTtp || pad != lastPad) {
Serial.printf("TTP223: %s GPIO2 pad: %s (%lu)\n", ttp ? "TOUCHED" : "-", pad ? "TOUCHED" : "-", (unsigned long)raw);
lastTtp = ttp;
lastPad = pad;
}
delay(50);
}// TTP223 touch module on an ESP32-S3-DevKitC-1, compared with the S3's own touch sensor.
// TTP223: VCC → 3V3, GND → GND, I/O → GPIO5 (HIGH while touched, default jumpers).
// Built-in touch: a bare wire or a coin of foil on GPIO2 (TOUCH2) — no module needed.
// On the S3 the touchRead() value RISES when touched (on the original ESP32 it falls).
constexpr uint8_t TTP_PIN = 5;
constexpr uint8_t TOUCH_PIN = 2;
uint32_t baseline = 0;
void setup() {
Serial.begin(115200);
pinMode(TTP_PIN, INPUT);
delay(200);
for (int i = 0; i < 8; i++) baseline += touchRead(TOUCH_PIN);
baseline /= 8;
Serial.printf("TTP223 on GPIO5, bare touch pad on GPIO2 (baseline %lu)\n", (unsigned long)baseline);
}
void loop() {
bool ttp = digitalRead(TTP_PIN) == HIGH;
uint32_t raw = touchRead(TOUCH_PIN);
bool pad = raw > baseline + baseline / 10; // 10 % above the untouched value; tune for your pad
static bool lastTtp = false, lastPad = false;
if (ttp != lastTtp || pad != lastPad) {
Serial.printf("TTP223: %s GPIO2 pad: %s (%lu)\n", ttp ? "TOUCHED" : "-", pad ? "TOUCHED" : "-", (unsigned long)raw);
lastTtp = ttp;
lastPad = pad;
}
delay(50);
}Expected serial output
TTP223 on GPIO5, bare touch pad on GPIO2 (baseline 21843)
TTP223: TOUCHED GPIO2 pad: - (21910)
TTP223: - GPIO2 pad: - (21877)
TTP223: - GPIO2 pad: TOUCHED (39512)TTP223 on GPIO5, bare touch pad on GPIO2 (baseline 21843) TTP223: TOUCHED GPIO2 pad: - (21910) TTP223: - GPIO2 pad: - (21877) TTP223: - GPIO2 pad: TOUCHED (39512)
Common errors
The GPIO2 pad triggers on its own
The 10 % threshold is too tight for a long wire. Raise it, or keep the wire under 10 cm.
TTP223 output stuck HIGH
Toggle mode is set (pad B bridged), or the module calibrated while your finger was on it — power-cycle with hands off.