Skip to content

Instantly share code, notes, and snippets.

@zamfi
Created June 5, 2017 18:05
Show Gist options
  • Save zamfi/5799b2e57b2f67510b5dd7433ddc971a to your computer and use it in GitHub Desktop.
Save zamfi/5799b2e57b2f67510b5dd7433ddc971a to your computer and use it in GitHub Desktop.
#include <CapacitiveSensor.h>
/*
* CapitiveSense Library Demo Sketch
* Paul Badger 2008
* Uses a high value resistor e.g. 10M between send pin and receive pin
* Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
* Receive pin is the sensor pin - try different amounts of foil/metal on this pin
*/
CapacitiveSensor sensor = CapacitiveSensor(5,6); // 10M resistor between pins 5 & 6, pin 6 is sensor pin, add a wire and or foil if desired
CapacitiveSensor sensor2 = CapacitiveSensor(5,A2); // 10M resistor between pins 5 & A2, pin A2 is sensor pin, add a wire and or foil if desired
void setup()
{
Serial.begin(9600);
}
void loop()
{
long start = millis();
long total1 = sensor.capacitiveSensor(30);
long total2 = sensor2.capacitiveSensor(30);
Serial.print(millis() - start); // check on performance in milliseconds
Serial.print("\t"); // tab character for debug windown spacing
Serial.print(total1); // print sensor output 3
Serial.print("\t");
Serial.println(total2);
delay(10); // arbitrary delay to limit data to serial port
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment