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.”)
DEVICE | NANO |
VCC | +5V |
GND | Ground |
SIG | D2 |
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);
}
}