1 #include <CapacitiveSensor.h>
4 * CapitiveSense Library Demo Sketch
6 * Uses a high value resistor e.g. 10M between send pin and receive pin
7 * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
8 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
12 CapacitiveSensor cs_4_2 = CapacitiveSensor(4, 2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
13 // pin 8 is sensor pin, add a wire and or foil
14 const int led = 13; // pin that the Piezo is attached to
15 int sensorMin = 50; // minimum sensor value
16 int sensorMax = 3200; // maximum sensor value
19 cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
26 long start = millis();
27 long total1 = cs_4_2.capacitiveSensor(30);
29 if (total1 > (sensorMax / 2 - sensorMin)) {
30 digitalWrite(led, HIGH);
34 digitalWrite(led, LOW);
38 Serial.print(millis() - start); // check on performance in milliseconds
39 Serial.print("\t Capacitance: "); // tab character for debug windown spacing
41 Serial.println(total1); // print sensor output 1
42 delay(1); // arbitrary delay to limit data to serial port