Skip to content

Instantly share code, notes, and snippets.

@AnandChowdhary
Last active September 11, 2018 09:33
Show Gist options
  • Save AnandChowdhary/42d67d1d07fc968a684f03e0705c4978 to your computer and use it in GitHub Desktop.
Save AnandChowdhary/42d67d1d07fc968a684f03e0705c4978 to your computer and use it in GitHub Desktop.
Capacitive Sensor
#include <CapacitiveSensor.h>
CapacitiveSensor c = CapacitiveSensor(13, 12);
float observedRightValue = 1750.0;
float observedLeftValue= 5000.0;
void setup() {
Serial.begin(9600);
}
void loop() {
float capacitorValue = c.capacitiveSensor(30);
// How far the finger is from left to right
if (capacitorValue > observedLeftValue || capacitorValue < observedRightValue) {
// The finger isn't touching the capacitor
} else {
float valueInCentimeters = (observedLeftValue - capacitorValue) / (observedLeftValue - observedRightValue) * 8;
Serial.println(valueInCentimeters);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment