Hi all,
I'm working on a project that utilizes a capacitive sensor as a rudimentary distance sensor with a wider range (rather than the cone provided by a standard I.R. distance sensor).
I'm having some trouble getting the values to be consistent and smooth out - the values returned jump around a lot and sometimes don't stay in the same general range, even when I leave my hand in the same exact spot.
I'm using Paul Badger's CapSense library, in a hardware set up as shown in the following image
http://dm.risd.edu/~pbadger/PhysComp/pmwiki/uploads/Devices/CapsenseSens9.jpg
I have the Arduino plugged in through a USB connection to my laptop, which is plugged in to a wall socket.
I tried using the Smoothing code found on the Arduino playground (http://www.arduino.cc/en/Tutorial/Smoothing), but I'm still getting some jumpy values and it seems to be less sensitive when I put my hand close, compared to when I don't use the Smoothing code.
Here is the base code I'm using to grab values:
#include <CapSense.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
* Best results are obtained if sensor foil and wire is covered with an insulator such as paper or plastic sheet
*/
CapSense cs_4_2 = CapSense(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil
// pin 2 is sensor pin, add wire, foil
// pin 4 is the receiver pin
//CapSense cs_4_5 = CapSense(4,5); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add wire, foil
//CapSense cs_4_8 = CapSense(4,8); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add wire, foil
void setup()
{
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(9600);
}
void loop()
{
long start = millis();
long total1 = cs_4_2.capSense(30);
// long total2 = cs_4_5.capSense(30);
// long total3 = cs_4_8.capSense(30);
Serial.print(millis() - start); // check on performance in milliseconds
Serial.print("\t"); // tab character for debug windown spacing
Serial.println(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
delay(10); // arbitrary delay to limit data to serial port
}
Any help with this would be greatly appreciated. Thanks again!