tech guy
Published

touch sensor

this project uses a touch sensor to turn on and off an led on pin 13.

IntermediateFull instructions provided18 minutes36,012
touch sensor

Things used in this project

Hardware components

touch sensor
×1
Arduino UNO
Arduino UNO
×1
USB-A to B Cable
USB-A to B Cable
×1
LED (generic)
LED (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

touch_sensor_ymqa8EeB5k.fzz

Code

touch switch 1000

Arduino
the modified code for a touch sensor.
int in = 2; 
int out = 13;  
int state = HIGH;  
int r;           
int p = LOW;    
long time = 0;       
long debounce = 200;   
void setup()
{
  pinMode(in, INPUT);
  pinMode(out, OUTPUT);
}
void loop()
{
  r = digitalRead(in);
  if (r == HIGH && p == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else 
      state = HIGH;
    time = millis();    
  }
  digitalWrite(out, state);
  p = r;
}

Credits

tech guy

tech guy

7 projects • 9 followers

Comments