# 7.3 Touch Sensor

## Hardware Wiring

![Touch Sensor](https://2341898987-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LCFDbcteyTR3tQSs-5x%2F-LCFE4dCRQBMq1ajywfh%2F-LCFELpqzxyrwkrQip1d%2F032_touch.jpg?generation=1526059594214151\&alt=media)

## Sketch

The code can be found at [Examples\_Arduino - sensor-kit-for-arduino - \_032\_Touch - \_032\_Touch.ino](https://github.com/LongerVisionRobot/Examples_Arduino/blob/master/sensor-kit-for-arduino/_032_Touch/_032_Touch.ino).

```
int Led=13;       // Define LDE Pin
int buttonpin=3;  // Define pin for touch sensor
int val;          // Define Variable val
void setup()
{
  pinMode(Led,OUTPUT);  // Define LED as output
  pinMode(buttonpin,INPUT); // Define touch sensor as input
}
void loop()
{
  val=digitalRead(buttonpin);// assign digital pin 3's reading to val
  if(val==HIGH) // anything detected by touch sensor, LED starts
  {
    digitalWrite(Led,HIGH);
  }
  else
  {
    digitalWrite(Led,LOW);
  }
}
```
