TouchIn – Read the state of a capacitive touch sensor


import touchio
from board import *

touch = touchio.TouchIn(A1)
while True:
    if touch.value:
class touchio.TouchIn(pin)

Use the TouchIn on the given pin.

Parameters:pin (Pin) – the pin to read from

Deinitialises the TouchIn and releases any hardware resources for reuse.


No-op used by Context Managers.


Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.


Whether the touch pad is being touched or not. (read-only)

True when raw_value > threshold.


The raw touch measurement as an int. (read-only)


Minimum raw_value needed to detect a touch (and for value to be True).

When the TouchIn object is created, an initial raw_value is read from the pin, and then threshold is set to be 100 + that value.

You can adjust threshold to make the pin more or less sensitive.