Touch Control Made Easy: A Beginner's Guide to TTP223 Sensors and ESP32 Touch Pins

Learn how to add touch control to your DIY electronics projects using the affordable TTP223 sensor module and the ESP32's built-in touch pins.
Jan 24, 2026 — 8 mins read — Electronics

Touch Control Made Easy: A Beginner's Guide to TTP223 Sensors and ESP32 Touch Pins

Let's talk about how we interact with our electronics projects. In most builds, when we want to give the device a command, we use a physical push button. You press it, it clicks, and something happens. But there's another, often more elegant way. You can use simple touch sensors, which let you control things just by getting your finger close.

I want to show you two great ways to add this feature. First, we can use a very cheap and common module called the TTP223. You can even use it to directly control things like a relay without any other electronics. Second, if you're using an ESP32 board, you might not need an extra module at all, because it has special pins with built-in touch sensitivity.


The video is sponsored by Altium Develop. Get your free trial here.


Understanding the TTP223 Touch Sensor

At its heart, the TTP223 is a small chip on a handy breakout board that senses when your finger is nearby. The module is simple, with just three pins to worry about: VCC for power, GND for ground, and an output pin in the middle. This output pin is what sends a signal to the rest of your circuit.

The magic happens on the other side of the board, where you'll find a small, printed touch pad. When you bring your finger close to that pad, it changes the electrical capacitance, and the chip detects that change. It then reacts by changing the state of its output pin, switching it from high to low voltage or vice versa. That signal is what you use to trigger an action, like turning on an LED or a relay.


How to Configure the Touch Sensor's Behavior

The cool thing about this sensor is you can change how it acts by connecting two little solder pads on the bottom, labeled A and B.

By default, with nothing connected, the module works like a momentary push button. When you touch it, the output turns on, and when you let go, it turns off. It doesn't stay in the new state. If you connect pad B with a small blob of solder, the sensor becomes a toggle switch. One touch turns the output on, and it stays on until you touch it again to turn it off.

Connecting pad A changes the starting state when you first apply power. With A connected, the output is active from the moment you turn it on. So, you can mix and match these connections to get the exact starting behavior and toggle style you want for your project.


Modifying the Sensor's Sensitivity

The TTP223 module is pretty sensitive right out of the box. Sometimes it's so sensitive you can trigger it just by getting your finger close without even touching the pad. This is actually useful if you want to hide it behind a plastic panel or a 3D-printed enclosure lid. If it's too sensitive for your needs, you can make it less sensitive by adding a small capacitor across the solder pads.

On the other hand, if you need more sensitivity, you can increase it by making the touch area bigger. I did this by soldering a wire to the touch pad and shaping it into a small coil. This creates a larger area to detect my hand's presence.

Just be careful with this mod, because if you make it too sensitive, it can become unreliable and might not reset properly between touches.


Using the Sensor with Any Microcontroller

The best part about this little sensor is how easy it is to connect to almost anything.

It works with a wide voltage range, from about 2 volts up to 5 volts. This means you can power it directly from a 3.3V ESP32 or a 5V Arduino Uno. To use it, you just connect its three pins: power to your board's power, ground to ground, and the sensor's output pin to any digital input pin on your microcontroller.

In your code, you treat it just like a regular button. You read the digital input pin, and if it's high or low (depending on your configuration), you know the sensor is being touched. It's a direct replacement for a physical button that doesn't require any pressing.


Unlocking the ESP32's Built-In Touch Pins

Now, if you're using an ESP32, you have another fantastic option that doesn't require any extra parts.

The ESP32 has 10 pins with special hardware for touch sensing built right in. These are regular GPIO pins that can also act as capacitive touch sensors. To use them, you just connect a wire to one of these special pins, like GPIO 4, 15, or 27. The other end of the wire can be connected to a piece of metal, like a bolt or a copper tape pad, to act as your touch surface.

There's one key difference from the TTP223 module: you need to make actual physical contact with the metal. Touching the plastic insulation on the wire won't work. When you touch the metal, the ESP32 detects a change in capacitance on that pin, and you can trigger an action in your code.


Writing the Code: A Simple Arduino IDE Example

Writing the code for the ESP32's touch pins is straightforward. In the Arduino IDE, you use special functions to read the touch-sensitive pins. First, you define which pins you are using as touch inputs. The code constantly reads the value from these pins, which is a number representing the capacitance it senses.

When you touch the connected wire, this number drops significantly. You set a threshold value to decide what counts as a "touch." In my example, I check if the reading goes below my threshold. When it does, I know that specific pin was touched, and I can then toggle an LED or trigger any other action I want. The code also prints which pin was touched to the Serial Monitor, so you can see it working. It’s a simple but powerful way to add touch control directly to your ESP32 project.

The full code from the video example is available below.

/*
 * ESP32 Touch Sensor Demo
 *
 * This demo showcases the ESP32's built-in capacitive touch sensing capability.
 * The ESP32 has 10 touch-sensitive GPIO pins that can detect when a finger
 * or conductive object touches or approaches the pin.
 *
 * Touch Pin Mapping:
 *  T0 = GPIO4, T1 = GPIO0, T2 = GPIO2, T3 = GPIO15, T4 = GPIO13
 *  T5 = GPIO12, T6 = GPIO14, T7 = GPIO27, T8 = GPIO33, T9 = GPIO32
 *
 * Hardware Setup:
 *  - Connect a wire or conductive pad to GPIO4 (Touch0) for touch input
 *  - Optional: Connect an LED to GPIO2 (built-in on many boards)
 *  - Optional: Add more touch pads to other touch-capable pins
 *
 * The touch sensor returns lower values when touched (more capacitance)
 * and higher values when not touched.
 */

// Touch sensor pins to monitor
const int TOUCH_PIN_1 = T0; // GPIO4
const int TOUCH_PIN_2 = T3; // GPIO15
const int TOUCH_PIN_3 = T7; // GPIO27

// LED pin for visual feedback
const int LED_PIN = 2// Built-in LED on most ESP32 boards

// Touch threshold - values below this indicate a touch
// Adjust this value based on your setup (typical range: 20-40)
const int TOUCH_THRESHOLD = 700;

// Variables for touch state tracking
bool ledState = false;
bool lastTouchState = false;
unsigned long lastDebounceTime = 0;
const unsigned long DEBOUNCE_DELAY = 50;

void setup() {
 // Initialize serial communication
 Serial.begin(115200);
 delay(1000); // Wait for serial monitor

 Serial.println();
 Serial.println("================================");
 Serial.println(" ESP32 Touch Sensor Demo");
 Serial.println("================================");
 Serial.println();
 Serial.println("Touch Pin Mapping:");
 Serial.println(" T0=GPIO4, T1=GPIO0, T2=GPIO2, T3=GPIO15, T4=GPIO13");
 Serial.println(" T5=GPIO12, T6=GPIO14, T7=GPIO27, T8=GPIO33, T9=GPIO32");
 Serial.println();
 Serial.println("Touch the wire connected to GPIO4 to toggle the LED");
 Serial.println("Lower values = touched, Higher values = not touched");
 Serial.println();

 // Initialize LED pin
 pinMode(LED_PIN, OUTPUT);
 digitalWrite(LED_PIN, LOW);
}

void loop() {
 // Read touch sensor values
 int touchValue1 = touchRead(TOUCH_PIN_1);
 int touchValue2 = touchRead(TOUCH_PIN_2);
 int touchValue3 = touchRead(TOUCH_PIN_3);

 // Detect touch on any of the three sensors
 bool currentTouchState = (touchValue1 < TOUCH_THRESHOLD) ||
              (touchValue2 < TOUCH_THRESHOLD) ||
              (touchValue3 < TOUCH_THRESHOLD);

 // Toggle LED on touch (with debounce)
 if (currentTouchState != lastTouchState) {
  lastDebounceTime = millis();
 }

 if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
  static bool stableTouchState = false;
  if (currentTouchState != stableTouchState) {
   stableTouchState = currentTouchState;
   if (stableTouchState) { // Rising edge - just touched
    ledState = !ledState;
    digitalWrite(LED_PIN, ledState);

    // Report which pin was touched
    if (touchValue1 < TOUCH_THRESHOLD) Serial.println("T0 (GPIO4) touched");
    if (touchValue2 < TOUCH_THRESHOLD) Serial.println("T3 (GPIO15) touched");
    if (touchValue3 < TOUCH_THRESHOLD) Serial.println("T7 (GPIO27) touched");
   }
  }
 }

 lastTouchState = currentTouchState;

 delay(10);
}


Conclusion: Choosing Your Touch Method

So, which method should you choose? It really depends on your project.

The TTP223 module is incredibly versatile and works with any microcontroller. It’s perfect when you want a reliable, configurable touch button that you can hide behind a surface.

The ESP32's built-in touch pins are a great, cost-free option if you're already using that board and don't mind making direct contact with a metal pad. Both methods let you move beyond physical buttons and create a sleek, modern interface for your electronics. I hope this gives you some ideas.

If you build a project with touch control, I'd love to hear about it. If you want to see some of my other projects and guides, make sure to subscribe to my YouTube channel.



Tools and Materials

Buying through the affiliate links I share below, costs you nothing extra, but the small commission I earn helps me buy new components and create more tutorials for the channel.

esp32 sensor touch
You might also enojy this

Smart Home Dashboard with ESPHome and CrowPanel HMI Advanced Screen

In this project, I’m going to show you how to set up a smart home dashboard using an ESPHome-compatible display. With this display, you’ll b...