Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#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()
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
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
You can’t perform that action at this time.