1.5k
In the following example we connect a capacitive touch switch to an Arduino and when a touch is detected we will switch on an LED. I used the following capacitive touch switch
It has 3 pins, VCC and GND for power and a SIG connection which you connect to your Arduino.
Code
#define TOUCH_SENSOR 3 //the touch sensor is connected to D3 of the Arduino int led = 9; // pin for the LED void setup() { Serial.begin(9600); pinMode(led, OUTPUT); pinMode(TOUCH_SENSOR, INPUT); } void loop() { int sensorValue = digitalRead(TOUCH_SENSOR); if(sensorValue) { Serial.println("Touch detected"); digitalWrite(led, HIGH); // turn LED on while(digitalRead(TOUCH_SENSOR) == HIGH); Serial.println("No Touch detected"); digitalWrite(led, LOW); // turn LED off } }
Links
TTP223B Digital Touch Sensor Capacitive Touch Switch Module DIY For Arduino