← Back to All Weeks
Week09

Week 9: Input Devices

Reading a capacitive touch input

I connected a TTP223 touch-sensor module to my XIAO RP2040 board and used its digital output to control the board’s LED. The module detects a change in capacitance when a finger approaches or touches the sensing area. The microcontroller receives an on/off signal; this program does not measure capacitance directly.

Group assignment: probing an input

Our group used a multimeter and oscilloscope to observe an input device. The multimeter helps us compare voltage levels, while the oscilloscope shows how a signal changes over time. The shared sensor work uses an MQ135, which is separate from the TTP223 used in the individual exercise below.

Our setup and observations are on our group assignment page. We need to retain the probe connections, voltage scale and time scale with the observations so that the signal can be understood.

Wiring the module to my board

I soldered the module’s VCC to 3.3 V, GND to the board ground and signal output to D9. The existing LED is connected to D1. Sharing a ground reference lets the board interpret the sensor output correctly.

ConnectionBoard pin or rail
TTP223 VCC3.3 V
TTP223 GNDGND
TTP223 signalD9
LED outputD1
TTP223 touch-module pinout
TTP223 touch-module pinout
Soldering the sensor wires
Soldering the sensor wires
The connected sensor and board
The connected sensor and board

Power check and program

I used a multimeter to check the sensor supply before running the program. The photographs show this check, but I have not transcribed a verified reading into the text. I then opened the sketch in the Arduino IDE and uploaded it to the board.

Checking the sensor power connection
Checking the sensor power connection
Checking the sensor supply voltage
Checking the sensor supply voltage

The sketch creates a touch object on D9. Each loop calls touch.update(), checks touch.isTouched() and sets D1 high or low. The original sketch depends on TouchSensorLib.h; its exact library source and version still need to be archived for a reproducible build.

#include <TouchSensorLib.h>

TouchSensor touch(D9);  // D9 on XIAO
int ledPin = D1;         // D1 on XIAO

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  touch.update();  // always call this first

  if (touch.isTouched()) {
    digitalWrite(ledPin, HIGH);  // LED ON while touching
  } else {
    digitalWrite(ledPin, LOW);   // LED OFF when not touching
  }
}
Opening the sketch in the Arduino IDE
Opening the sketch in the Arduino IDE
Uploading the touch sketch
Uploading the touch sketch
The sketch after upload
The sketch after upload

Demonstration and reflection

The video records the touch-input test with the LED as visible feedback. Touching and releasing the sensor lets me compare an input change with an output response. It demonstrates detection rather than a calibrated measurement of force or contact area.

Recorded touch-input and LED test

The main lesson was to describe what the sensor actually reports. A touch module can hide the capacitance processing inside its own circuit, leaving a simple digital interface for the microcontroller. Keeping that distinction clear makes both the wiring and the code easier to explain.

Source code

The download preserves the original sketch, including its library dependency.

A version without the missing touch library

I prepared a library-free version with Codex assistance, keeping D9 as the touch input and D1 as the LED output. It uses digitalRead(), waits for a stable state for 30 ms and logs TOUCHED or RELEASED at 115200 baud. It builds for the XIAO RP2040 with Arduino-Pico 4.5.3; it is not a recovered copy of TouchSensorLib.h.

The module's active level and momentary/toggle setting still matter. The new source makes the active level explicit, so I can adjust it to the actual TTP223 instead of treating every module configuration as identical. I will record supply and output levels, then touch and release several times while observing both the serial state and LED. I still need that physical retest and the actual board revision.