Skip to content
Free Delivery on Orders Above Rs 999/- Pan-India
Cash on Delivery Available for Orders above Rs.500/- and Upto Rs 3000/-
SAVE more when you BUY more. Upto 30% Off on BULK PURCHASE
GST Invoices for Your Business
Dedicated Technical Support Team
Safely Delivering Genuine Products PAN INDIA

TTP223 Touch Sensor with Arduino: Pinout, Modes and Code

TTP223 Touch Sensor with Arduino: Pinout, Modes and Code
-
Written By - Robocraze -
📅 Updated on 22 Oct 2026
✨ Summarize with AI
✅ Prompt copied

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:

  1. The sensor continuously monitors its touch electrode.

  2. A finger approaches or touches the sensing area.

  3. The capacitance changes.

  4. The TTP223 recognises the touch and changes its OUT signal.

  5. 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:

  1. Touch the TTP223 sensing area.

  2. The module changes its OUT signal.

  3. A microcontroller or compatible driver circuit detects the signal.

  4. The driver activates the relay.

  5. 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.

Excerpt

Learn how the TTP223 capacitive touch sensor works, its pinout, momentary and toggle modes, Arduino code, relay control and touch detection through glass or plastic.

Frequently Asked Questions

1. What do the A and B pads on TTP223 do?

On many TTP223 modules, the A and B configuration pads select different operating modes, such as momentary and toggle behaviour. The exact pad arrangement depends on the board version. Check the module's markings or documentation before changing the solder connections, and disconnect power before making modifications.

2. Does TTP223 work through glass?

Yes, a TTP223 module can often detect touch through thin glass or plastic because it senses changes in capacitance rather than requiring direct electrical contact. Detection depends on cover thickness, the sensing electrode, mounting and nearby materials. Test the assembled enclosure to confirm reliable operation.

3. Can TTP223 work with 3.3V?

Many TTP223 modules support a supply range that includes 3.3V, but confirm the specification of your particular board. When connecting it to an ESP32 or another 3.3V microcontroller, ensure the output signal stays within the GPIO's voltage limits.

4. How do I make it a toggle switch?

You can use a module configuration that supports toggle operation, if available, or implement toggle behaviour in software. In software, detect one transition per touch and change the output state once. Make sure the code matches the module's output polarity and avoids repeated toggling while the sensor remains active.

5. Is TTP223 better than a push button?

It depends on the application. TTP223 is useful for smooth touch surfaces, compact controls and interfaces without moving button contacts. A mechanical push button is often better when you want tactile feedback and a physical action. Capacitive touch sensing can be more sensitive to moisture, electrical noise and enclosure design.

Prev Post
Next Post

Leave a comment

Please note, comments need to be approved before they are published.

Thanks for subscribing!

This email has been registered!

Shop the look

Choose Options

Edit Option
Back In Stock Notification
Compare
Product SKU Description Collection Availability Product Type Other Details

Choose Options

this is just a warning
Login
Shopping Cart
0 items
FREE SHIPPING!
₹100 OFF
₹200 OFF
₹999
₹2500
₹4900
WhatsApp Chat Chat