Werktags vor 14:00 Uhr bestellt = am selben Tag versendet 30 Tage Widerrufsrecht 1 Jahr Garantie
← Zurück zur Übersicht

Schaltplan und Codebeispiel

So schließt du den Touchsensor TTP223B an einen Arduino UNO oder ESP32 an, mit einem Beispiel-Sketch, den du direkt hochladen kannst.

TTP223B kapazitiver Berührungssensor Demo

Dieses Projekt zeigt das TTP223B kapazitive Berührungssensormodul. Wenn du das kapazitive Touch-Pad berührst, gibt der Sensor ein HIGH-Signal aus, das die eingebaute LED des Arduino einschaltet und den Status im Serial Monitor ausgibt.

Anschlussplan: Touchsensor TTP223B an einem Arduino UNO
Anschlussplan · Zum Vergrößern klicken
Anschlusstabelle: Touchsensor TTP223B an einem Arduino UNO
Anschlusstabelle · Zum Vergrößern klicken
TTP223B_Capacitive_Touch_Sensor_Demo.ino · kompiliert und getestet
/*
 * ==================================================================
 *  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 kapazitiver Berührungssensor-Demo

Diese Schaltung liest digitale Signale vom TTP223 kapazitiven Berührungssensor aus und gibt den Zustand auf der eingebauten LED des ESP32 wieder. Wenn du das Sensorkontaktfeld berührst, wird der Signalpin HIGH, wodurch die onboard LED aufleuchtet und Berührungsereignisse im Serial Monitor ausgegeben werden. Das Modul wird direkt mit 3.3V versorgt, um eine sichere Logikkompatibilität zu gewährleisten.

Anschlussplan: Touchsensor TTP223B an einem ESP32 DevKit V1
Anschlussplan · Zum Vergrößern klicken
Anschlusstabelle: Touchsensor TTP223B an einem ESP32 DevKit V1
Anschlusstabelle · Zum Vergrößern klicken
ESP32_TTP223_Capacitive_Touch_Sensor_Dem.ino · kompiliert und getestet
/*
 * ==================================================================
 *  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

Zuletzt angesehen

Digitales Multimeter

Digitales Multimeter

€ 9,95
Ansehen