Op werkdagen vóór 14:00 uur besteld = dezelfde dag verzonden en in 98% van de gevallen de volgende dag in huis. Gratis retourneren 30 dagen bedenktijd 1 jaar garantie
← Tillbaka till översikten

Kopplingsschema och kodexempel

Så här kopplar du Touchsensor TTP223B till en Arduino UNO eller ESP32, med ett exempel­sketch som du kan ladda upp direkt.

TTP223B Capacitive Touch Sensor Demo

This project demonstrates the TTP223B capacitive touch sensor module. When you touch the capacitive sensing pad, the sensor outputs a HIGH signal which turns on the Arduino's built-in LED and prints the status to the Serial Monitor.

Kopplingsschema: Touchsensor TTP223B på en Arduino UNO
Kopplingsschema · Klicka för att förstora
Kopplingstabell: Touchsensor TTP223B på en Arduino UNO
Kopplingstabell · Klicka för att förstora
TTP223B_Capacitive_Touch_Sensor_Demo.ino · kompilerad och testad
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : TTP223B Capacitive Touch Sensor Demo
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : Touch sensor TTP223B
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

// Pin definitions
const int touchPin = 2;
const int ledPin = 13;

int lastState = LOW;

void setup() {
  pinMode(touchPin, INPUT);
  pinMode(ledPin, OUTPUT);

  Serial.begin(115200);
  Serial.println(F("TTP223B Touch Sensor Initialized"));
}

void loop() {
  int touchState = digitalRead(touchPin);

  // Control onboard LED based on touch input
  digitalWrite(ledPin, touchState);

  // Print message on state change
  if (touchState != lastState) {
    if (touchState == HIGH) {
      Serial.println(F("Touch detected!"));
    } else {
      Serial.println(F("Touch released."));
    }
    lastState = touchState;
  }

  delay(20);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

ESP32 TTP223 Capacitive Touch Sensor Demo

This circuit reads digital signals from the TTP223 capacitive touch sensor and reflects the state on the ESP32's built-in LED. When you touch the sensor pad, the signal pin goes HIGH, illuminating the onboard LED and printing touch events to the Serial Monitor. The module is powered directly with 3.3V for safe logic compatibility.

Kopplingsschema: Touchsensor TTP223B på en ESP32 DevKit V1
Kopplingsschema · Klicka för att förstora
Kopplingstabell: Touchsensor TTP223B på en ESP32 DevKit V1
Kopplingstabell · Klicka för att förstora
ESP32_TTP223_Capacitive_Touch_Sensor_Dem.ino · kompilerad och testad
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : ESP32 TTP223 Capacitive Touch Sensor Demo
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : Touch sensor TTP223B
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

const int TOUCH_PIN = 4;   // D4 on ESP32 DevKit V1
const int LED_PIN   = 2;   // Onboard LED on ESP32 DevKit V1

int lastState = LOW;

void setup() {
  Serial.begin(115200);
  pinMode(TOUCH_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
  Serial.println("TTP223 Touch Sensor Initialized.");
}

void loop() {
  int touchState = digitalRead(TOUCH_PIN);

  if (touchState != lastState) {
    if (touchState == HIGH) {
      digitalWrite(LED_PIN, HIGH);
      Serial.println("Touch detected!");
    } else {
      digitalWrite(LED_PIN, LOW);
      Serial.println("Touch released.");
    }
    lastState = touchState;
    delay(50); // Simple debounce delay
  }
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online