Summary
Learn how to connect a TTP223 capacitive touch sensor to Arduino or ESP32. Explore its pinout, operating modes, sample code, relay control, enclosure considerations and common troubleshooting fixes.
The TTP223 is a capacitive touch sensor module that detects a finger touch and provides a digital output, making it a simple alternative to a mechanical push button. Most common TTP223 modules operate from about 2–5.5V, and many use a default momentary mode: the output changes while touched and returns when released. You can connect one to an Arduino or ESP32 to control an LED, trigger a relay through a suitable driver circuit, or build a touch-sensitive control panel.
The TTP223 Touch Switch Module is a compact option for experimenting with capacitive touch input in DIY electronics projects.
What Is the TTP223?
The TTP223 is a capacitive touch-sensing IC commonly found on small touch switch modules. Instead of relying on a mechanical contact, it detects changes in capacitance when a finger approaches or touches the sensing area.
A typical module has three main connections:
-
VCC: Power supply.
-
GND: Ground.
-
OUT: Digital output indicating the touch state.
When a touch is detected, the output changes between LOW and HIGH according to the module's configuration. The default behaviour on many boards is active-HIGH momentary operation, but module variants may differ.
The TTP223 is useful for projects that need a simple touch input without a moving button. Common applications include touch-controlled LEDs, interactive DIY projects, appliance interfaces and touch-sensitive enclosures.
TTP223 Pinout
Most basic TTP223 modules expose three pins: VCC, GND and OUT. Check the labels printed on your specific board before wiring it, as the pin order can vary.
|
Pin |
Function |
Connection |
|---|---|---|
|
VCC |
Power input |
Compatible supply, commonly 3.3V or 5V |
|
GND |
Ground |
Microcontroller GND |
|
OUT |
Digital output |
Arduino or ESP32 digital input |
The sensor output is a logic signal, not a power output for driving loads directly. Use a transistor, MOSFET or suitable relay driver circuit when controlling loads that require more current than a microcontroller pin can safely supply.
For ESP32 projects, use a compatible supply and ensure the output signal does not exceed the GPIO's voltage tolerance. A module powered at 5V may output a signal level that is not safe for direct connection to a 3.3V-only GPIO unless the board design limits or shifts that voltage.
How Does Capacitive Touch Sensing Work?
The TTP223 detects touch by measuring a change in capacitance at its sensing electrode. When a finger approaches the electrode, it changes the electrical conditions around the sensor. The IC detects that change and updates its output.
A typical touch event works like this:
-
The sensor continuously monitors its touch electrode.
-
A finger approaches or touches the sensing area.
-
The capacitance changes.
-
The TTP223 recognises the touch and changes its OUT signal.
-
The microcontroller reads the output and performs an action, such as switching an LED.
Unlike a mechanical push button, the module does not need metal contacts to close physically. This reduces mechanical wear at the sensing interface, although the module can still be affected by electrical noise, moisture, grounding and the material covering its sensing surface.
TTP223 A and B Modes
Many TTP223 modules support two selectable operating behaviours: momentary (non-toggle) and toggle (latching). The exact mode depends on the IC configuration and the solder pads or jumpers provided on the module.
|
Mode |
Behaviour |
Example application |
|---|---|---|
|
A: Momentary / non-toggle |
Output changes when touched and returns to its inactive state after release |
Touch input, temporary activation |
|
B: Toggle / latching |
Each recognised touch changes the output state; the state remains until the next touch |
Touch-controlled light or an on/off interface |
The exact polarity and configuration depend on the module. Some boards also provide options for active-HIGH or active-LOW output behaviour. Check the module's markings and documentation before assuming which solder pad selects a mode.
How to choose the right mode
Use momentary mode when you want the output to represent whether the sensor is currently being touched. This is useful for a touch input that behaves similarly to a push button.
Use toggle mode when each touch should switch a device on or off. For example, one touch could turn an LED on and the next touch could turn it off without needing to keep a finger on the sensor.
If your module has configuration pads, switch off power before soldering or changing their connections. Do not assume that every TTP223 board uses the same pad layout.
Connect a TTP223 to Arduino
The simplest way to test a TTP223 is to connect its OUT pin to an Arduino digital input and use it to control an LED.
Wiring table
|
TTP223 module |
Arduino Uno |
|---|---|
|
VCC |
5V, if supported by the module |
|
GND |
GND |
|
OUT |
Digital pin 2 |
For an ESP32, connect OUT to a suitable GPIO input and use a compatible supply and signal voltage. The wiring is otherwise similar, but check the exact board's voltage requirements.
Arduino code: touch to switch an LED
This example turns an LED on while the sensor output is HIGH and off when it is LOW. It assumes a module configured for active-HIGH momentary operation.
const int touchPin = 2;
const int ledPin = 13;
void setup() {
pinMode(touchPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int touchState = digitalRead(touchPin);
if (touchState == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
On an Arduino Uno, pin 13 is connected to the onboard LED on many board versions. You can also use an external LED with a suitable series resistor.
If the LED turns off when you touch the sensor, the module may use active-LOW output logic. In that case, reverse the HIGH and LOW conditions in the code.
Code for toggle behaviour in software
If your module is in momentary mode but you want each touch to switch the LED state, you can implement toggle behaviour in the Arduino code. The following example detects a change from LOW to HIGH and toggles the LED once per touch.
const int touchPin = 2;
const int ledPin = 13;
int previousTouchState = LOW;
int ledState = LOW;
void setup() {
pinMode(touchPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int currentTouchState = digitalRead(touchPin);
if (currentTouchState == HIGH &&
previousTouchState == LOW) {
ledState = !ledState;
digitalWrite(ledPin, ledState);
delay(50); // Simple debounce / noise delay
}
previousTouchState = currentTouchState;
}
This is a basic demonstration, not a universal touch-debouncing solution. If your module's output is active-LOW, change the edge detection accordingly. For a more robust interface, use time-based debounce logic and test how the sensor behaves with repeated touches.
Using the TTP223 to Control a Relay
A TTP223 can act as a touch input for a relay-controlled project, but the sensor output should not be assumed to drive a relay coil directly. A relay coil typically needs more current than the sensor output or microcontroller GPIO can provide.
A safer arrangement uses the TTP223 output as a control signal for a suitable transistor driver or relay module. The driver switches the relay coil, while the relay contacts control the separate load circuit.
A basic control path is:
-
Touch the TTP223 sensing area.
-
The module changes its OUT signal.
-
A microcontroller or compatible driver circuit detects the signal.
-
The driver activates the relay.
-
The relay contacts switch the intended load.
Choose a relay module that matches the control voltage and logic level. Check whether its input is active-HIGH or active-LOW, and follow the module's wiring instructions.
Safety: If the relay is switching mains voltage, use a properly rated and enclosed relay assembly, maintain appropriate insulation and clearances, and avoid exposed live connections. For beginner projects, test the logic using a low-voltage load first.
For a project using an Arduino, you can refer to How to Connect a Relay with Arduino.
Using the TTP223 Behind Glass or Plastic
A capacitive touch sensor can often detect a finger through a thin, non-conductive cover, such as plastic or glass. This makes the TTP223 useful for touch controls where the electronics need to sit behind a smooth surface.
However, the maximum usable cover thickness depends on the module's sensing electrode, sensitivity, installation and the material itself. A thick cover, nearby metal, moisture or poor grounding may reduce touch sensitivity or cause false triggers.
For best results:
-
Start with a thin plastic or glass cover and test it before final assembly.
-
Place the sensing electrode close to the intended touch area.
-
Keep metal parts away from the sensing surface where possible.
-
Secure the module so it does not move relative to the cover.
-
Test repeatedly under the actual conditions in which the project will be used.
Do not assume that every TTP223 module will reliably detect touch through any glass or plastic thickness. Test the complete enclosure and adjust the design if touch detection is inconsistent.
TTP223 vs a Mechanical Push Button
Both a TTP223 and a mechanical push button can provide an input to an Arduino, but they work differently.
|
Feature |
TTP223 touch sensor |
Mechanical push button |
|---|---|---|
|
Detection method |
Capacitive touch sensing |
Physical contact |
|
Moving contacts |
No moving button contacts |
Mechanical contacts |
|
Touch through a cover |
Often possible with a suitable non-conductive cover |
Generally requires physical access to the button |
|
Wiring |
Typically VCC, GND and OUT |
Often requires a button and suitable pull-up or pull-down arrangement |
|
Environmental sensitivity |
Can be affected by moisture, noise and nearby materials |
Can be affected by contact wear and mechanical conditions |
|
Best use |
Smooth touch panels and compact touch interfaces |
Clear physical feedback and conventional button controls |
The TTP223 is useful when you want a flat touch surface without a moving button. A mechanical button may be preferable when you need tactile feedback or a more predictable physical action.
Troubleshooting Common TTP223 Problems
|
Problem |
Possible cause |
What to check |
|---|---|---|
|
Touch is not detected |
Incorrect wiring, insufficient power or unsuitable cover |
Verify VCC/GND, test without the cover and inspect the sensing surface |
|
Output stays HIGH |
Toggle mode, active logic or false triggering |
Check the module configuration and test away from interference |
|
LED behaves in reverse |
Active-LOW output logic |
Reverse the HIGH/LOW conditions in the code |
|
Sensor triggers by itself |
Electrical noise, moisture or nearby metal |
Improve mounting, keep the surface dry and separate the sensor from noisy wiring |
|
Touch works only sometimes |
Cover too thick, unstable power or poor placement |
Test the bare module, check the supply and reduce the cover thickness |
|
Relay does not switch |
Driver or relay input is incompatible |
Verify relay input polarity, driver wiring and supply requirements |
Test the sensor's OUT pin independently before troubleshooting the rest of the project. Reading the pin with digitalRead() or observing it with a multimeter can help establish whether the problem lies with the touch sensor or the connected circuit.
Conclusion
The TTP223 is a compact capacitive touch sensor that provides a simple digital input for Arduino and ESP32 projects. Understanding its pinout, output polarity and momentary or toggle behaviour makes it easier to use in touch-controlled LEDs, relay interfaces and DIY control panels.
Start with a basic VCC, GND and OUT connection, verify the output using a short sketch, and then add the load or enclosure. If the module will control a relay, use a suitable driver rather than powering the relay coil directly from the sensor output.
The TTP223 Touch Switch Module is a practical starting point for experimenting with touch-based interfaces. Check its exact voltage requirements and configuration before connecting it to your microcontroller.