Arduino capacitive touch example

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

Capacitive Touch

It has 3 pins, VCC and GND for power and a SIG connection which you connect to your Arduino.

Code

[c]

#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
}
}

[/c]

Links

TTP223B Digital Touch Sensor Capacitive Touch Switch Module DIY For Arduino

Related posts

Arduino and GY-21P readings on a web page

MPL3115A2 sensor readings displayed on a web page

Adafruit Neopixel shield examples