Source: https://mokxi.com/learn/arduino-touch-sensor
Updated: 2026-10-25

Learn

# How to use a touch sensor with an Arduino

Intermediate

Written by the Mokxi team, updated October 25, 2026

Start building free Open the editor

Or see every lesson.

- 455 parts on the bench
- 43 boards running now
- 1.00x real time, on every board

Hold the pointer on the touch pad to flip the units

A TTP223 on pin 2 flips an AHT20’s reading on a 16x2 LCD between C and F, on a simulated ATmega328P. Hold the pointer on the pad.

Wire VCC to 5 V or 3.3 V, GND to GND and SIG to a digital pin. SIG goes HIGH while a finger is on the pad and LOW when it lifts. There is no switch inside, so it needs no pull-up resistor and it never bounces: one touch is one clean change on the pin.

The circuit above is a climate display on an Uno: an AHT20 temperature and humidity sensor and a 16x2 LCD sharing the I2C pins, and a TTP223 touch pad on pin 2. Press Run, then hold the pointer on the pad. About 60 ms later SIG goes HIGH, and the display flips between Celsius and Fahrenheit. Touch it again to flip it back.

## What you need

- An Arduino Uno
- A TTP223 touch sensor module
- An AHT20 sensor and a 16x2 I2C LCD (for the climate display)
- Jumper wires

## Wiring

Part and pin | Goes to | Note

TTP223 SIG | Pin 2 | HIGH while touched

TTP223 VCC | 3.3 V | Anything from 2 V to 5.5 V works

TTP223 GND | GND |

AHT20 SDA and SCL | A4 and A5 | The I2C pins

LCD SDA and SCL | SDA and SCL | The same two wires, by the AREF pin

## How a touch sensor works

The round pad on the board is one plate of a capacitor, and your finger is the other. The TTP223 chip watches the pad all the time, and a touch adds a few picofarads. When it sees that, it drives SIG. SIG is a real output that drives both high and low, so the Arduino reads it with plain INPUT, no INPUT_PULLUP and no resistor.

In the climate display the module runs from the 3.3 V pin, so SIG goes to 3.3 V, which the Uno still reads as HIGH. That is handy, because the same module works on a 3.3 V board like an ESP32 without any changes.

## A touch lamp: one touch on, one touch off

The sketch below toggles the LED on pin 13 each time a touch starts. It remembers whether the pad was touched last time through the loop, and acts only when it goes from not touched to touched, so holding a finger there does not flicker the lamp. We touched the pad at one second and again at two seconds. It printed "touch the pad", "lamp on" and "lamp off", once each.

There is no debounce code, and none is needed. Compare that with a pushbutton, whose contacts bounce, so the same sketch on a button needs a 20 to 50 ms debounce.

A touch toggle on pin 2

## The 60 ms rule

The TTP223 takes up to 60 ms to decide a touch is real, and the same again for a release. In the climate display SIG went HIGH 60 ms after the finger landed. A tap shorter than that is never seen at all. In the toggle sketch run, a 40 ms tap between the two real touches changed nothing.

That suits a button. It does not suit a fast game, or a drum pad that should catch quick taps. For many keys or quick taps, an MPR121 handles twelve pads over I2C and lets you set its own thresholds.

## The power-on trap

For about half a second after power comes on, the chip measures the pad and ignores it. A finger that is already on the pad when that time ends becomes part of the pad. We held a finger on it through power-up and kept it there for a second: nothing happened. Only after lifting it and touching again did the sketch print "lamp on".

On a real project it is easy to hit this by resting a hand on the case while plugging it in. Keep fingers off the pad for the first moment, or tell your users to.

## The two jumpers on the back

Most TTP223 boards have two solder pads on the back, marked A and B. Out of the bag both are open, and SIG is HIGH while touched. Bridge A and SIG turns active low: LOW while touched. Bridge B and the chip toggles on each touch by itself, so SIG stays HIGH after one touch and goes LOW after the next. In the simulator these are the activelow and toggle properties of the part.

## Common mistakes

Adding a pull-up or INPUT_PULLUP. SIG drives both ways, so it does not need one.

Touching the pad while it powers up. The first touch then does nothing. Lift off and touch again.

Expecting it to catch very short taps. Anything under about 60 ms is missed.

Writing a toggle that flips on every loop while the finger is down. Act on the change from not touched to touched, as above.

Putting the pad behind thick plastic. A thin case works, but thick or metal covers stop it feeling a finger on a real board.

## Questions

How do I connect a TTP223 touch sensor to an Arduino?

VCC to 5 V or 3.3 V, GND to GND and SIG to a digital pin. Read it with digitalRead(): HIGH while touched, LOW when not. Use pinMode(pin, INPUT); it needs no pull-up.

Do I need to debounce a touch sensor?

No. There is no mechanical contact to bounce. The chip already filters the touch for up to 60 ms before it changes SIG, so one touch gives one clean edge.

Why does my touch sensor not work the first time?

It calibrates for about half a second after power-up. If a finger is on the pad when that ends, the chip treats it as part of the pad. Lift your finger and touch again.

Can a touch sensor work as a toggle switch by itself?

Yes. Bridge the B jumper on the back and SIG flips on each touch, so it stays HIGH until the next one. Or leave the jumpers alone and toggle in code, as the sketch on this page does.

Related

## Keep going

Arduino MPR121: 12-Key Capacitive Touch Piano Arduino Button Debounce: See the Bounce, Then Fix It Arduino LCD I2C 16x2: Wiring, Code, Scrolling Text Pull-Up Resistors and the Floating Input They Fix Arduino Vibration Sensor (SW-420): Wiring, Code Arduino FSR: Force Sensor Wiring, Code, Readings The TTP223, pin by pin How the TTP223 is modeled The Arduino Uno simulator The project page, with the full sketch Intermediate

## Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.

Start building free Open the editor
