Hey guys
I am working on a "capacitive distance sensor".
So far the work on my project is going well
The only problem I have is that the return values from the Arduino
are fluctuating perfectly (meaning every few values) from low to high values (from about 40 to 100)
The following is my code, and the graph is attach'd.
The higher the value, the closer my hand is.
Note the 'grass' when nothing is around the aluminum foil (lowest point).
The foil is about 3cm x 3cm;
grounding cap is 100pF (101);
using a 15M resistor;
My plan is to output the values through the PWM port, scaling is easy
but I just need stable values.
Any suggestions?
Thanks;
#include <CapSense.h>
CapSense cs_4_2 = CapSense(4,2); // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil
CapSense cs_4_5 = CapSense(4,5); // 10 megohm resistor between pins 4 & 6, pin 6 is sensor pin, add wire, foil
CapSense cs_4_8 = CapSense(4,8); // 10 megohm resistor between pins 4 & 8, pin 8 is sensor pin, add wire, foil
long rx1=0;
byte rx2=0;
String rxc1=0;
String rxc2=0;
String final=0;
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();
rx1 = cs_4_2.capSense(10); //R channel
rx1/=2;
Serial.println(rx1);
delay(10);
}
Image, taken from Processing.