This video is for Educational purposes.
Source Code:
(1).Reads the value from the touch sensor and print to the Serial Monitor:
const int SENSOR_PIN = 2; // the Arduino's input pin that connects to the sensor's SIGNAL pin
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// initialize the Arduino's pin as aninput
pinMode(SENSOR_PIN, INPUT);
}
void loop() {
// read the state of the the input pin:
int state = digitalRead(SENSOR_PIN);
// print state to Serial Monitor
Serial.println(state);
}
(2).Toggles LED on UNO board,when the sensor is touched.
#define ctsPin 2
// Pin for capactitive touch sensor
int ledPin = 13;
// pin for the LED
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ctsPin, INPUT);
}
void loop()
{
int ctsValue = digitalRead(ctsPin);
if (ctsValue == HIGH)
{
digitalWrite(ledPin, HIGH);
Serial.println("TOUCHED");
}
else{
digitalWrite(ledPin,LOW);
Serial.println("not touched");
}
delay(500);
}
*****************************************************************************