The first touch
Three wires, no library, and a sketch that prints a line each time the pad is touched and released. VCC goes to your board's logic supply, SIGNAL to a plain input: D2 on an Uno, GPIO 25 on an ESP32, GPIO 4 on an ESP32-S3, GP15 on a Pico. The red LED on the block lights with every touch.
Three wires
GND to GND. VCC to your board's logic supply: 5V on an Uno, 3V3 on the three 3.3 V boards. SIGNAL to a digital pin. NC stays unconnected.
The input pin is the same as in the push-button book: D2 on an Uno, GPIO 25 on an ESP32, GPIO 4 on an ESP32-S3, GP15 on a Pico. None of them is read by the chip at boot or tied up with its flash memory. Any other plain digital pin works too.
Plug in with your hand clear of the pad. The chip learns the pad in its first half second, and a finger there becomes part of what it thinks is nothing.
The sketch
pinMode(TOUCH_PIN, INPUT) makes the pin an input with nothing of its own
switched on. The block's chip drives SIGNAL HIGH and LOW itself, so the pin
needs no pull-up. digitalRead(TOUCH_PIN) returns HIGH while the pad is
touched.
The loop reads the pin as fast as it can and prints only when the reading differs from the last one, so each touch is two lines rather than a stream. No debounce is needed: the chip decides once per look at the pad and drives the line cleanly.
What you should see
The serial monitor at 115200 prints a pair of lines for each touch:
HIGH touched
LOW released
HIGH touched
LOW releasedThe red LED on the block lights for exactly as long as a line says HIGH. If it lights and the monitor stays quiet, the fault is the pin number or the SIGNAL wire. If neither changes, it is VCC or GND.
The sketch compiles for an ESP32-S3 and an Uno. Here is the same block on an Uno and on a Pico-format board, lighting an XL LED block when touched:
The code
No library. pinMode makes the pin an input and digitalRead returns HIGH while the pad is touched. The sketch prints only when the reading changes. Change TOUCH_PIN to the pin you wired SIGNAL to.
/*
Touch Sensor - first read TK43 / /p/tk43
Wiring. Count from the square pad on the TinkerBlock board, pad
up, header at the bottom:
GND -> GND
VCC -> 5V on an Uno; 3V3 on an ESP32, ESP32-S3 or Pico
(touched, SIGNAL gives your pin whatever VCC is)
NC -> nothing (unconnected on the board)
SIGNAL -> D2 on an Uno, GPIO 25 on an ESP32, GPIO 4 on an
ESP32-S3, GP15 on a Raspberry Pi Pico
Arduino IDE
Tools > Board your board, e.g. ESP32S3 Dev Module
Tools > Port the one that appears when you plug in
Tools > USB CDC On Boot Enabled (ESP32-S3 only)
No library needed.
Keep your hand off the pad while the board powers up.
*/
// The GPIO number SIGNAL is wired to.
// Uno: 2. ESP32: 25. ESP32-S3: 4. Pico: 15.
const int TOUCH_PIN = 4;
int last = LOW;
void setup() {
Serial.begin(115200);
pinMode(TOUCH_PIN, INPUT); // the chip drives SIGNAL both ways
}
void loop() {
int reading = digitalRead(TOUCH_PIN);
if (reading != last) { // print only when it changes
if (reading == HIGH) {
Serial.println("HIGH touched");
} else {
Serial.println("LOW released");
}
last = reading;
}
}INPUT, with no pull-up: the chip drives SIGNAL both ways itself. Keep your hand off the pad while the board powers up, because the chip spends its first half second learning what untouched looks like. The sketch compiles for an ESP32-S3 and an Uno.
View on GitHub · blocks/tk43-tp223-touch-sensor/arduino/touch_first_read/touch_first_read.ino @ v1.0The same read in MicroPython, for an ESP32, an ESP32-S3 or a Pico. Pin.IN makes the pin an input and value() returns 1 while the pad is touched.
"""
Touch Sensor - first read, MicroPython TK43 / /p/tk43
Wiring. Count from the square pad on the TinkerBlock board, pad
up, header at the bottom:
GND -> GND
VCC -> 3V3 (never 5V: touched, SIGNAL gives your pin VCC)
NC -> nothing (unconnected on the board)
SIGNAL -> GPIO 25 on an ESP32, GPIO 4 on an ESP32-S3,
GP15 on a Raspberry Pi Pico
Thonny
Run > Configure interpreter MicroPython (ESP32) or
MicroPython (Raspberry Pi Pico)
Save it to the board as main.py to run it on every power-up.
Nothing to install: machine is built in.
"""
from machine import Pin
# The GPIO number SIGNAL is wired to. ESP32: 25. ESP32-S3: 4. Pico: 15.
TOUCH_PIN = 4
touch = Pin(TOUCH_PIN, Pin.IN) # the chip drives SIGNAL both ways
last = 0
while True:
reading = touch.value()
if reading != last: # print only when it changes
print("HIGH touched" if reading else "LOW released")
last = readingThere is no Uno here: an Uno cannot run MicroPython. No pull argument, because the chip drives SIGNAL both ways. Stop it with Ctrl-C in Thonny's shell.
View on GitHub · blocks/tk43-tp223-touch-sensor/micropython/touch_first_read.py @ v1.0When it does not work
The chip saw the touch and drove SIGNAL HIGH, so the fault is after it. Check TOUCH_PIN names the pin SIGNAL is really on, that the wire is on SIGNAL (the fourth hole) and not NC (the third), and that GND is shared.
VCC or GND is missing, or the cable is one pin over. Count from the square pad: GND, VCC, NC, SIGNAL. If the wiring is right, unplug the board, keep your hand off the pad, and plug it in again: a finger on the pad at power-up spoils its baseline.
Something is on the pad or pressing against it: a wire lying across it, a finger holding the board. Clear it and reset. The chip never times a touch out, so it stays HIGH for as long as the thing stays.
Set Tools > USB CDC On Boot to Enabled and upload again. Without it the S3's USB port does not bring up a serial port at boot, so the sketch runs with nowhere to print. The red LED lighting tells you the block itself is fine.
One touch on, the next off, with the memory in the sketch.
A touch that latches →Edit this page — content/books/tp223-touch-sensor/the-first-touch.mdx
Questions about this product
See what other owners have asked, and read their solutions.
This page covers several products. Choose yours to see the right discussions.
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.