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
10 * Schema: http://i.stack.imgur.com/FMI00.png
16 CapacitiveSensor cs_2_3 = CapacitiveSensor(2, 3); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
17 CapacitiveSensor cs_2_4 = CapacitiveSensor(2, 4);
18 CapacitiveSensor cs_2_5 = CapacitiveSensor(2, 5);
23 const int led = 13; // pin that the Led is attached to
24 int sensorMin = 50; // minimum sensor value
25 int sensorMax = 3200; // maximum sensor value
28 cs_2_3.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
35 long start = millis();
36 long total1 = cs_2_3.capacitiveSensor(30);
37 long total2 = cs_2_4.capacitiveSensor(30);
38 long total3 = cs_2_5.capacitiveSensor(30);
40 if (total1 > (sensorMax / 2 - sensorMin)) {
41 digitalWrite(led, HIGH);
42 Serial.println("Primo");
46 if (total2 > (sensorMax / 2 - sensorMin)) {
47 digitalWrite(led, HIGH);
48 Serial.println("Secondo");
51 if (total3 > (sensorMax / 2 - sensorMin)) {
52 digitalWrite(led, HIGH);
53 Serial.println("terzo");
56 Serial.print(millis() - start); // check on performance in milliseconds
57 Serial.print("\t Capacitance 1: "); // tab character for debug windown spacing
59 Serial.print(total1); // print sensor output 1
60 Serial.print("\t 2: "); // tab character for debug windown spacing
62 Serial.print(total2); // print sensor output 1
63 Serial.print("\t 3: "); // tab character for debug windown spacing
64 Serial.println(total3); // print sensor output 1
66 delay(1); // arbitrary delay to limit data to serial port