Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk14 min

How to Use a TTP223 Touch Sensor With a Raspberry Pi

Connect a TTP223 breakout to Raspberry Pi 3.3 V, ground, and a GPIO input, then read its digital output with GPIO Zero. The key is matching your code to the module’s polarity and direct or toggle mode.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Connect a TTP223 breakout’s VCC to the Raspberry Pi’s 3.3 V rail, GND to a Pi ground pin, and SIG or OUT to a GPIO input. With the module set for direct, active-high output, GPIO Zero can read a touch as a button press. Check the breakout’s output polarity and direct-versus-toggle setting before relying on that behavior: modules can be configured differently, and the code must match the board.

What the TTP223 does

A TTP223 touch sensor is a capacitive touch switch. Its breakout board detects a touch and presents the result as a digital signal; the Raspberry Pi reads that signal as either a high or low GPIO input. It is not an analog sensor that reports how hard or how long you press. A typical breakout has three connections: VCC for power, GND for ground, and SIG or OUT for the signal.

As an Amazon Associate I earn from qualifying purchases.

The signal has two configuration choices to account for. Polarity determines whether a touch produces a high or low level. Output behavior determines whether the signal follows the touch or remains latched after it. In direct mode, the output changes with the touch. In toggle mode, a touch switches the output state, which stays changed until another touch. Those settings affect both what you observe and how your Python program should interpret it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Think of the sensor as a switch that reports its state, rather than as a device that sends a stream of measurements. Your program can respond to the change from idle to touched, or use the current output level as a simple on/off state. This distinction matters most when choosing between direct and toggle behavior: in direct mode the signal corresponds to contact, while in toggle mode it records which state the sensor is currently latched in.

#1 Best Overall
ALAMSCN 20PCS TTP223 Capacitive Touch Switch Button Sensor Module Self Locking for Arduino…
  • The module is based on a touch-sensing IC TTP223 capacitive touch switch module, it allows you to avoid the trouble of conventional push-type buttons.
  • Size: 15*11mm
  • Modes: jog, self-locking
  • Power Supply: 2.5V-5.5V
  • Package Include: 20PCS TTP223 Capacitive Touch Switch Sensor

Parts and Raspberry Pi pin choices

For a basic input test, you need a Raspberry Pi with its 40-pin GPIO header populated, a TTP223 breakout, and jumper wires. A breadboard is optional. The sensor itself needs only power, ground, and one signal wire. Freenove’s TTP223 project lists an LED and a 220 Ω resistor as additional parts for an LED demonstration; they are not required to read the sensor.

This example uses BCM GPIO17, which is physical header pin 11. These are two names for the same connection, not interchangeable numbering systems: GPIO Zero’s Button(17) uses the BCM GPIO number. Physical pin 1 is a 3.3 V supply pin, physical pin 6 is ground, and physical pin 11 is GPIO17. Raspberry Pi documentation describes the GPIO header and GPIO Zero, which is included by default in Raspberry Pi OS.

When following a wiring diagram, check whether its numbers refer to BCM GPIO names or physical header positions. A program that asks for GPIO17 is referring to the GPIO signal, not the seventeenth pin down the header. In this example, that signal is on physical pin 11. Mixing the two numbering schemes can put a wire on an unintended header contact, so use both names when checking the example against the Pi.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Wire the breakout to the Pi

Freenove gives the TTP223 module supply range as 2.0–5.5 V. For a direct connection to Raspberry Pi GPIO, power the breakout from 3.3 V. Pi GPIO uses 3.3 V logic, and a module powered from 5 V may produce an output that is not safe to connect directly. Do not assume that a breakout’s output is Pi-safe just because its supply range includes 5 V.

TTP223 breakout Raspberry Pi connection Purpose
VCC 3.3 V, physical pin 1 or 17 Supplies the sensor within the documented module range.
GND Any Pi ground pin, such as physical pin 6 Provides a shared electrical reference.
SIG or OUT GPIO17, physical pin 11, for this example Carries the digital output; configure this GPIO as an input.
  1. Identify the breakout pins. Read the labels on your board and check its documentation for the pin order. Do not assume that every board places VCC, GND, and SIG in the same order.
  2. Power off the Pi while wiring. Connect VCC to 3.3 V and GND to a ground pin. The sensor and Pi must share ground.
  3. Connect the output. Wire SIG or OUT to GPIO17, then check that it is not accidentally connected to a power pin.
  4. Inspect the connections before powering up. Confirm the 3.3 V and ground wires are on the intended header pins and that the breakout is oriented according to its labels.

The shared ground is important because the GPIO input needs the same electrical reference as the sensor output. VCC powers the breakout; SIG or OUT is the one connection that carries the touch state to the Pi. The Pi pin connected to SIG should therefore be configured as an input, not as a power connection or an output.

The stated 2.0–5.5 V range describes the cited module’s supply specification; it does not mean that every output voltage in that range is appropriate for a Pi input. A direct hookup is simplest when the breakout itself is supplied at 3.3 V. If you have a board that has been powered at 5 V, do not reconnect its output to the Pi unless you know the exact circuit limits the signal safely.

Read a direct, active-high signal in Python

For the common direct, active-high arrangement, the sensor output is high while touched and low while idle. GPIO Zero’s Button class can represent that as a button-like input. The example below prints a message for each transition:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from gpiozero import Button
from signal import pause

touch = Button(17, pull_up=False)
touch.when_pressed = lambda: print("Touched")
touch.when_released = lambda: print("Released")
pause()

Save the code in a Python file and run it in a terminal on the Pi. Touch the sensor pad and check that the program prints Touched; lift your finger and check for Released. The pull_up=False setting suits the assumed active-high signal: the input is treated as pressed when the GPIO is high. This example depends on that output configuration, so do not treat its behavior as a universal default for every TTP223 breakout.

Rank #2
5PCS TTP223 Capacitive Touch Switch Module TTP223B Digital Touch Sensor Module Capacitive Touch Sensor Switch
  • Capacitive type touch switch module The module is based on a touch detection IC (TTP223B)'s. Under normal conditions, the module output low, low-power mode to mode; touch of a finger when the corresponding position, the module will output high, the mode is switched to fast mode; when for 12 seconds without touching, the mode and switch to low power mode.
  • For Jog type: the initial state is low, high touch, do not touch is low (similar touch of a button feature)
  • Power supply for 2 ~ 5.5V DC
  • Control Interface: A total of three pins (GND, VCC, SIG), GND to ground, VCC is the power supply, SIG digital signal output pin;
  • Power Indicator: Green LED, power on the right that is shiny;

The two callbacks make it easier to test both transitions. If you see only one message, compare what the code expects with what the module is actually outputting. A sensor in toggle mode may remain in its changed state after you lift your finger, so a release event will not necessarily correspond to the moment your finger leaves the pad. First test the module’s electrical behavior, then choose the software logic that matches it.

GPIO Zero is included by default in Raspberry Pi OS according to Raspberry Pi’s hardware documentation, so this is a straightforward starting point on that system. The example assumes the GPIO Zero interface and the direct, active-high behavior described above. If you use another GPIO library or a different operating system setup, the method for configuring and reading the pin can differ; keep the same wiring and logic assumptions in mind.

Match the code to the board’s output mode

Some TTP223 breakouts expose solder pads or jumpers for selecting output polarity and behavior. Tontek’s TTP223N family information describes selectable output characteristics, while ThinkRobotics documents a breakout variant with four combinations of high/low polarity and no-lock/self-lock operation. Those examples show why the exact board matters; their configuration details should not be generalized to other modules.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Before changing code, find out which mode your particular board uses. Inspect its labels and documentation for polarity and for terms such as direct, toggle, no-lock, or self-lock. The names and physical configuration pads are board-specific. A setting described for one breakout may not map to another board’s pads, so do not guess which solder bridge to alter.

Direct, active-high

Use the example as written when the output is high during touch and low at rest. A press event means the signal became high; a release event means it returned low. This is the behavior to check for when you want the software’s pressed state to track a finger on the sensor.

Direct, active-low

If your breakout produces a low level on touch and a high level at rest, invert the logical interpretation in software. In GPIO Zero, Button offers an active_state setting for defining which electrical level counts as pressed. For example, if the low level represents touch, use Button(17, pull_up=False, active_state=False). Verify the observed idle and touched levels before settling on this setting; breakout labeling and defaults vary.

In practical terms, active-low does not mean the sensor failed or that its signal is unusable. It means the logical event you call “pressed” corresponds to a low electrical level. Make one change at a time: establish the idle level, touch the pad and note the changed level, then configure the software to treat that level as active. Keeping the electrical level separate from the human meaning of “touched” helps avoid reversing the logic twice.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Toggle or self-lock mode

In toggle mode, the output does not indicate that a finger is currently on the pad. Instead, each touch changes the latched output state. A callback named when_pressed still reports a transition into the program’s logical pressed state, but that state may remain after your finger leaves. Treat the output as a stored on/off state, not as a live touch duration. To make a project react to each touch, detect output changes and decide what each transition should do; do not interpret a sustained high or low as continuous contact.

Rank #3
Lonely Binary 12-Pack TTP223 Capacitive Touch Sensor for C++ & ESP32
  • 【PACK OF 12 MODULES】12 TTP223 touch sensor modules for prototyping, repairs, or multiple projects — suitable for hobbyists, makers, and educators.
  • 【GOLD EDITION ENIG FINISH】Immersion gold (ENIG) plating for good conductivity and corrosion resistance. Lead-free, RoHS-compliant manufacturing.
  • 【WIDE VOLTAGE COMPATIBILITY】Supports both 3.3V and 5V MCU systems — works with Raspberry Pi Pico, ESP32, ESP32-S3, and other microcontroller projects.
  • 【CAPACITIVE TOUCH SENSITIVITY】Single-channel TTP223 IC for touch detection — replaces mechanical buttons in IoT devices, smart switches, lamps, and interactive electronics.
  • 【EASY INTEGRATION】Compact size with clear pinouts (VCC, GND, I/O) and low power consumption for DIY applications.

For example, a program may use a change into the active state as one event and a change back as the next event. In toggle mode, those changes can happen on successive touches rather than on touch and release. That is why a simple “print touched while the signal is high” interpretation can be misleading: the high state may persist between touches. The module’s mode, not merely the Python callback name, determines what the signal represents.

Test and debug the input

If the program’s behavior differs from the expected press-and-release cycle, troubleshoot from the physical connection inward. A continuous “Touched” state, no response, or erratic readings can arise from incorrect wiring, a mismatched polarity assumption, toggle mode, or confusion between GPIO numbering and physical header numbering.

  • The program reports touch continuously: Check VCC, GND, and SIG against the board labels, and verify that the signal wire reaches GPIO17 rather than a supply pin. Then check whether the output is active-low or the module is in toggle mode.
  • Touching the pad has no visible effect: Confirm that the breakout is powered from 3.3 V and that Pi ground and module ground are connected. Verify the selected pin in code and the physical wire location. Check the module’s output mode and polarity rather than assuming it uses the common active-high direct configuration.
  • The readings seem unreliable: Recheck the pin numbering scheme: GPIO17 is physical pin 11 in this example. Ensure the chosen GPIO is configured as an input and the signal is not connected to a power pin. Inspect the jumper or solder-pad configuration and the wiring for a loose connection.
  • The board was powered from 5 V: Do not connect its output directly to a Pi GPIO unless you know the exact circuit limits that signal safely. Disconnect it and use 3.3 V module power for the standard direct-wiring setup.

Make one change at a time when testing: first verify power and shared ground, then the signal pin and numbering, and finally the board’s output mode. That sequence helps separate wiring faults from software assumptions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A useful check is to reason through the signal path in order. Is the breakout receiving power on its labeled VCC pin? Is its ground connected to a Pi ground? Does its labeled signal pin reach the GPIO named in the program? Is that GPIO being treated as an input? Only after those checks should you adjust the code’s active-state interpretation. This avoids trying to solve a wiring problem by changing polarity settings, or trying to solve a polarity mismatch by rewiring the supply.

If the board offers jumpers or solder pads, include their current positions in the diagnosis. A configuration change can alter whether the output is active-high or active-low, and whether it follows a touch or latches. Look up the instructions for the specific breakout rather than relying on a photograph of a similar-looking module. Breakouts can share the TTP223 name while differing in pin order and configuration details.

Optional: use the sensor to control an LED

An LED demonstration adds an output to the basic sensor input. Freenove’s project parts list specifies a 220 Ω resistor for its LED project. The resistor is a current-limiting component; do not wire an LED directly to a GPIO without suitable current limiting. Keep the sensor’s SIG connection on an input and use a separate GPIO for the LED output. The cited Raspi.cc example uses BCM GPIO18 as an input and GPIO23 as an LED output with RPi.GPIO, but that is an illustrative project pattern, not a guarantee that this library is the preferred choice on every current Raspberry Pi OS release. Choose software that is supported in your installed OS and keep the sensor’s polarity and toggle-mode handling consistent with the actual board.

The LED and resistor are optional because the TTP223 already provides a digital signal that can be observed in the terminal. An LED can make a beginner project’s response visible, but it adds a second circuit to wire and a separate GPIO to configure as an output. Keep the two roles distinct: the sensor’s signal goes to an input, while the LED is controlled from an output through its current-limiting resistor.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The Raspi.cc example is useful as an illustration of a different project arrangement: it uses BCM GPIO18 for input and GPIO23 for an LED output with RPi.GPIO. Treat those as BCM GPIO numbers, not physical header numbers. The example demonstrates the idea of reading the sensor and controlling an LED, but the cited information does not establish that this library is the right choice for every current Raspberry Pi OS installation. GPIO Zero is another documented option and is included by default in Raspberry Pi OS.

Rank #4
D-FLIFE 100pcs TTP223 Touch Switch Module Capacitive Sensor Switch DIY for Arduino Raspberry Pi
  • 100pcs TTP223 Capacitive Switch Button Module Self-Lock Switch Button Module High Low Level Output
  • TTP223 Capacitive Switch Button Module
  • The power supply of the TTP223 touch switch button module is 2.5 to 5.5V.
  • These TTP223 touch switch button modules are made of CCL with premium quality and long service life.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What to check when choosing a breakout

There is no single universal TTP223 breakout layout established by the cited documentation. Before connecting a module, check the pin order and labels, the permitted supply range, its default output polarity, whether the output is direct or toggle, and whether configuration pads or jumpers are present. A module’s supply specification alone does not establish that its output is safe for a Pi GPIO when powered at every voltage in that range.

For the simplest Pi project, favor a board whose pin labels and mode settings are documented, power it at 3.3 V, and test the idle and touched output behavior before writing application logic. A breakout’s default mode may not match the example in this guide, so use the observed signal behavior to decide how the code should interpret it.

When comparing listings or modules, look beyond the product name. Confirm that the pictured and documented pin order agrees with the labels on the board you receive. Check the stated supply range, but separately determine how the output behaves at the voltage you plan to use. Look for clear information about active-high versus active-low behavior and direct versus toggle or self-lock operation. If the listing shows configuration pads or jumpers, check that its documentation explains their settings.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A breadboard and jumper wire set can be useful if you want to keep the connections temporary and easy to inspect, but neither changes the sensor’s requirements: it still needs power, ground, and a signal connection. A basic module is the central component; the LED and 220 Ω resistor are optional additions for a separate demonstration. No universal board price or single breakout configuration follows from the cited sources, so compare the actual specifications rather than choosing on a presumed standard layout.

Frequently asked questions

Can I connect a TTP223 directly to a Raspberry Pi?

For the standard direct hookup, power the module at 3.3 V, connect its ground to Pi ground, and connect SIG or OUT to a GPIO input. Check the particular breakout’s documentation and output behavior first. Do not assume an output from a module powered at 5 V is safe for a Pi GPIO.

Which GPIO pin should I use?

This guide uses BCM GPIO17, which is physical header pin 11. You can choose another appropriate GPIO input, but make sure the BCM number in your code matches the physical header contact used for SIG or OUT. Do not confuse a GPIO number with a physical pin number.

Does a TTP223 output high or low when touched?

That depends on the breakout’s polarity setting. The common direct, active-high arrangement goes high when touched and low while idle, but some boards or configurations may be active-low. Check the module’s documentation and verify its idle and touched behavior before choosing the software’s active state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What is the difference between direct and toggle mode?

In direct mode, the output follows the touch state. In toggle mode, each touch changes a latched output state, which remains changed until another touch. Use direct mode if you want the signal to represent current contact; interpret toggle mode as a stored on/off state.

Best Value
HiLetgo 10pcs TTP223B Capacitive Touch Switch Module Touch Sensor Switch Digital Capacitive Touch Sensor Switch DC 2~5.5V
  • This is the "momentary" variety of the touch sensor - touch and it turns on, release and it turns off.
  • Positive and negative can be used as a touch surface,can replace the traditional touch button.
  • Four M2 screws positioning holes for easy installation.Module can be installed in such as surface plastic, glass of non-metallic materials.
  • In addition to the thin paper ( non-metallic ) covering the surface of the module , as long as the correct location of the touch , you can make hidden in the walls, desktops and other parts of buttons.
  • The module is based on a touch-sensing IC (TTP223B) capacitive touch switch module. In the normal state, the module output low, low power consumption; When a finger touches the corresponding position, the module output high, if not touched for 12 seconds, switch to low-power mode.

Do I need an LED or resistor to read the sensor?

No. The basic input test needs the sensor, jumper wires, and the Pi connection to power, ground, and a GPIO input. For an LED demonstration, use a separate GPIO output and a suitable current-limiting resistor; Freenove’s project list specifies 220 Ω for its example.

Frequently Asked Questions

Can I connect a TTP223 directly to a Raspberry Pi?

For the standard direct hookup, power the module at 3.3 V, connect its ground to Pi ground, and connect SIG or OUT to a GPIO input. Check the particular breakout’s documentation and output behavior first. Do not assume an output from a module powered at 5 V is safe for a Pi GPIO.

Which GPIO pin should I use?

This guide uses BCM GPIO17, which is physical header pin 11. Make sure the BCM number in your code matches the physical header contact used for SIG or OUT; GPIO numbering and physical pin numbering are different.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does a TTP223 output high or low when touched?

That depends on the breakout’s polarity setting. The common direct, active-high arrangement goes high when touched and low while idle, but some boards or configurations may be active-low. Verify the idle and touched behavior before choosing the software’s active state.

What is the difference between direct and toggle mode?

In direct mode, the output follows the touch state. In toggle mode, each touch changes a latched output state that remains changed until another touch. Treat toggle mode as a stored on/off state, not as an indication that a finger is still touching the pad.

Do I need an LED or resistor to read the sensor?

No. The sensor input test needs only power, ground, and a signal connection. For an LED demonstration, use a separate GPIO output and current-limiting resistor; Freenove’s parts list specifies 220 Ω for its LED project.

The Bottom Line

Connect VCC to 3.3 V, GND to Pi ground, and SIG/OUT to a GPIO input such as BCM GPIO17 (physical pin 11). Start with the GPIO Zero example only if your module is direct and active-high; check the breakout’s documentation and match the code to its polarity and toggle setting. Keep 5 V-powered outputs off Pi GPIO unless the exact circuit is known to be safe.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
ALAMSCN 20PCS TTP223 Capacitive Touch Switch Button Sensor Module Self Locking for Arduino…
ALAMSCN 20PCS TTP223 Capacitive Touch Switch Button Sensor Module Self Locking for Arduino…
Size: 15*11mm; Modes: jog, self-locking; Power Supply: 2.5V-5.5V; Package Include: 20PCS TTP223 Capacitive Touch Switch Sensor
$6.99
Bestseller No. 2
5PCS TTP223 Capacitive Touch Switch Module TTP223B Digital Touch Sensor Module Capacitive Touch Sensor Switch
5PCS TTP223 Capacitive Touch Switch Module TTP223B Digital Touch Sensor Module Capacitive Touch Sensor Switch
Power supply for 2 ~ 5.5V DC; Power Indicator: Green LED, power on the right that is shiny;
$5.99
Bestseller No. 4
D-FLIFE 100pcs TTP223 Touch Switch Module Capacitive Sensor Switch DIY for Arduino Raspberry Pi
D-FLIFE 100pcs TTP223 Touch Switch Module Capacitive Sensor Switch DIY for Arduino Raspberry Pi
TTP223 Capacitive Switch Button Module; The power supply of the TTP223 touch switch button module is 2.5 to 5.5V.
$10.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.