Improving Capacitive Sensor Speed

Trying a little project using the Capacitive Sensor Library. The sensors are actually copper tubing caps connected via 1M ohm resistors to digital pins on a UNO. The setup seems to work okay as I get increased readings when I touch the sensors, so it should suit my needs, but the response to touching the sensors is slow, with a 1-2 second lag. I looked into the library code to see if there was any way to accelerate the measurement process, but got lost pretty quickly (still a newbie). Any suggestions?

Here's my code (demo sketch):

#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   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
CapacitiveSensor   cs_4_6 = CapacitiveSensor(4,6);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
long start;
void setup()                    
{
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   Serial.begin(9600);
   start = millis();
}

void loop()                    
{
    
    long total1 =  cs_4_2.capacitiveSensor(30);
    long total2 =  cs_4_6.capacitiveSensor(30);
    long total3 =  cs_4_8.capacitiveSensor(30);

    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for debug window spacing

    Serial.print(total1);                  // print sensor output 1
    Serial.print("\t");
    Serial.print(total2);                  // print sensor output 2
    Serial.print("\t");
    Serial.println(total3);                // print sensor output 3

    
}

OF course it's slow! You are charging a capacitor through a 1 meg resistor with no ground connection.
Try connecting the resister between the Arduino pin and the Arduino ground, not in series with the pin, but parallel.

The whole point of capacitive sensing is that it should work without touching the sensor.

The metal part should be behind an electric insulator.
Sensors I made still worked through a sheet of perspex or 6mm of glass.
Must have some ground plane near though.

Maybe you should try PPT223 sensor boards.
Leo..

1 Like

What I'm trying to do is to make a quick and dirty touch point (actually, a few of them) to control some servos. They will likely end up behind some sort of barrier, but that doesn't solve the issue of slow responsiveness.

I was following the Arduino playground example for this: [Arduino Playground - CapacitiveSensor].

Here's the schematic for my current setup.

.

Are you suggesting something like this?

Incorrect. The resistor charges through the parasitic capacitance of the sensing surface. What you suggest will do nothing.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.