/* Project: Touch Switch Function: LED will be off when touch switch activated */ const int touchswitchPin=7; //touch switch attached to digital pin 7 const int ledPin = 12; //LED attached to digital pin 12 int touchswitchState=0; //store the value of touch switch //************************************************** void setup() { pinMode(touchswitchPin,INPUT);//set touchswitchPin as INPUT pinMode(ledPin,OUTPUT); //set ledPin as OUTPUT Serial.begin(9600); //initialize serial communications at 9600 bps } void loop() { touchswitchState=digitalRead(touchswitchPin);//read the value of pin7 Serial.println(touchswitchState); //print it in serial monitor if(touchswitchState==HIGH) //if the touch switch activated { digitalWrite(ledPin,LOW); //turn LED off } else { digitalWrite(ledPin,HIGH); //turn LED on } }