Arduino as Capacitive Sensor

Ok first thing, please just modify your post and put the code in # (code brackets - takes up less room)

Have you tried that code on your arduino? I suggest you conect up the circuit and try that code. Just copy everything from '// CapSense.pde' downwards straight into the arduino IDE and upload it.

The resistor doesn't have to be 10M, anything near will do if you don't have a 10M.

Then use the serial monitor to work out what values you get 'normally' and when you are touching it.

Then at the start of the code you need to define your LED. Use pin 13 as it has an inbuilt LED (on newer boards).

So the code should look like this at the top:

int  i;
unsigned int x, y;
float accum, fout, fval = .07;    // these are variables for a simple low-pass (smoothing) filter - fval of 1 = no filter - .001 = max filter

int ledPin =  13;    // LED connected to digital pin 13

[edit]You also need to define the pin, just stick it after defining serial in setup:

void setup() {
 Serial.begin(9600);
  pinMode(ledPin, OUTPUT);

[/edit]

Then after Serial.println( (long)fout, DEC); // Smoothed Low to High
you want to put an 'if' command.

Eg:

Serial.print((long)x, DEC);    // raw data - Low to High
Serial.print( "   ");
Serial.print((long)y, DEC);    // raw data - High to Low
Serial.print( "   ");
Serial.println( (long)fout, DEC); // Smoothed Low to High

if(x > 50)
  digitalWrite(ledPin, HIGH);
else
  digitalWrite(ledPin, LOW);
delay(20) //Delay for good measure! (not strictly necessary but might as well have it)
}//Last line of code - nothing after this!

Put the 'if' value as just below the lowest value you get when you touch the wire.

There may be a stupid error in that code but it should work.
Say if it doesn't work and i'll fix it :slight_smile:

Mowcius