Arduino: Capacitive Touch Switch (TTP223B)

It operates as any other momentary switch (in that it “closes” when you are touching it, and “opens” when you let go. As opposed to “toggling” between “on” and “off.”)

DEVICENANO
VCC+5V
GNDGround
SIGD2

On these Nanos, pin 13 is the built-in LED, so you don’t have to wire in anything else.

//Demonstrating Capacitive Touch Switch (TTP223B) on Arduino Nano

int ledPin = 13;
int touchPin = 2;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(touchPin, INPUT);
}

void loop() {
  int touchValue = digitalRead(touchPin);
  
  if (touchValue == HIGH) {
    Serial.println("TOUCHED");
    digitalWrite(ledPin, HIGH);
  }
  else {
    digitalWrite(ledPin, LOW);
  }
}

This entry was posted in Arduino and tagged . Bookmark the permalink.