Skip to content

Instantly share code, notes, and snippets.

@shfitz
Last active November 17, 2020 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shfitz/4a7607a407333446e8b9870f2e3c8226 to your computer and use it in GitHub Desktop.
Save shfitz/4a7607a407333446e8b9870f2e3c8226 to your computer and use it in GitHub Desktop.
#include <CapacitiveSensor.h>
// create an instance of the library. pin 2 is the sensor
CapacitiveSensor capsense = CapacitiveSensor(4, 2);
void setup() {
// start serial
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// store the sense value - argument is number of samples to take
long val = capsense.capacitiveSensor(30);
// if the sensor val is greater than 30, turn the LED on
if(val > 30){
digitalWrite(LED_BUILTIN, HIGH);
}else{ // otherwise turn it off
digitalWrite(LED_BUILTIN, LOW);
}
// print the info to the serial monitor
Serial.print("capacitive sense value: ");
Serial.println(val); // print sensor output
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment