Capacitive Touch Button Demo

This demo shows a TTP223 capacitive touch button module in use. The following image is a greatly enlarged view of both sides of the module:

A TTP223 capacitive touch button module (both sides shwn)

As can be seen in the above image, the TTP223 has three connections: GND, I/O and VCC. VCC is the power connection and requires 2.0V to 5.5V. GND is ground and the I/O connection signals high when the sensor is touched and low otherwise (by default - see below).

NOTE: The signal on the I/O connection of the module can be altered by shorting the pads marked A and B. Furthermore, the sensitivity can be altered by soldering a capacitor to the vacant SMD solder pad. I'm not covering any of that here: you can find more information in the article How to Use a TTP223-Based Touch Switch on Hackster.io.

The I/O connection can be used to directly control a circuit. The simplest example, that of switching a LED on and off, can be seen in the following circuit:

Capacitive touch button circuit design without microcontrollerBreadboard circuit design

Capacitive touch button circuit without microcontroller as built on breadboardBreadboard circuit as built

The circuit can be seen operating in the following video:

The other option is to attach the TTP223 I/O connection to a microcontroller. Again taking a simplistic approach, the following circuit shows an Arduino Uno being used to read the state of the TTP223 on pin 2 and to switch an LED on and off using pin 4. Yes, the circuit has exactly the same outcome as the previous one, but this is a proof of concept not a practical circuit!

Capacitive touch button circuit design with Arduino UnoBreadboard circuit design

Capacitive touch button circuit with Arduino Uno as built on breadboardBreadboard circuit as built

Here's another video showing this circuit working:

And here's a sample of serial output:

Serial ouput from capacitive touch button circuit running on Arduino Uno

The source code for the latter demo is available from the cahamo/demo-projects repository on GitHub. The relevant code will be found in the ttp223-touch-button--uno directory. All the C++ code is in src/main.cpp.

This demo is a PlatformIO project for use with Visual Studio Code. It can be modified for use with the Arduino IDE simply by copying the code from ttp223-touch-button--uno/src/main.cpp into a new, blank Arduino API project. No library code is required.