CapacitiveSensorDue

Hi!

I am having trouble making the CapacitiveSensorDue library to work on Arduino Due...

I have used CapacitiveSensor library on Arduino UNO and 2009 before, with no trouble.

1Mohm resistor between sendPin and recvPin

I tried different TIMEOUT values, and I tried using different pins, buy I always get "-1" from the read() method.

Going nuts here, please help!

#include <CapacitiveSensorDue.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.
    */

CapacitiveSensorDue cs_4_2 = CapacitiveSensorDue(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired

void setup()
{
Serial.begin(9600);
cs_4_2.setTimeout(100);
cs_4_2.calibrate();
}

void loop()
{
long total1 = cs_4_2.read(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
}

Where is the link to that CapacitiveSensorDue library? Did you read the sticky note at the top of the forum?

Hi!

The library is available in the arduino library section

http://playground.arduino.cc//Main/CapacitiveSensor?from=Main.CapSense

I don't get what you want to point out about the sticky note, which I guess is the one on how to use the forum, right??

The library is available in the arduino library section

Arduino Playground - HomePage

That's the playground section, the Arduino library section is just that part that consists of the libraries included in the IDE. The CapacitiveSensor library is not part of the IDE.

I don't get what you want to point out about the sticky note, which I guess is the one on how to use the forum, right??

That note explicitly states that you should provide links to all hardware and software (as libraries are) that are not coming directly from Arduino itself.

You wrote that you're using 1M? resistors, the library maintainer suggests 10M?. Have you tried that value too? The Due uses a lower voltage (3V3) than the UNO/Duemillanove (5V) so you might not be able to use the same hardware. What values are you experimenting with?

Sorry about that confusion

Thank you for the suggestion! I'll try different values of the resistor, and see if that works.

From my experience, bigger values of resistance lead to bigger time for the capacitor to charge, therefore bigger count returned by the read() function.

So if it is already overflowing, I don't think adding resistance will help, so I'll try smaller values and see what happens.

I don't think the 3.3V has anything to do here, since all the hardware I am using is a resistor between the sendPin and the receivePin.

If I can't pull it, I think I'll have to use the MPR121 to sense the faders.

From my experience, bigger values of resistance lead to bigger time for the capacitor to charge, therefore bigger count returned by the read() function.

So if it is already overflowing, I don't think adding resistance will help, so I'll try smaller values and see what happens.

Have you tried to set another timeout value?

I don't think the 3.3V has anything to do here, since all the hardware I am using is a resistor between the sendPin and the receivePin.

The time to load your (simple) capacitor depends not only on the resistor used but also on the voltage you apply, so this factor is relevant although I don't know to what extend. How did you build your sensor? May I ask you to post a picture of your sensor hardware.

Here's a picture of the set up.
http://hackatonmusical.com/wp-content/uploads/2013/06/esquema.jpg
Instead of the UNO, the arduino is a DUE.

And here's the schematic which is even easier to understand.
http://hackatonmusical.com/wp-content/uploads/2013/06/esquematico.jpg

The capacitor is actually formed by an aluminium foil and your hand, which right now I replaced for a simple wire which with an open end to the air.

The time to load your (simple) capacitor depends not only on the resistor used but also on the voltage you apply, so this factor is relevant although I don't know to what extend.

Well, actually it doesn't. The time for an RC circuit to charge the capacitor is given by a thing called "time constant", which in this case is the number you get by multiplying the value of the resistance you use times the capacitance. The time it takes to fully charge is approximately 5 time constants -> 5.R.C.
This is why this library works! It measures how much it takes the circuit to charge the capacitor sending pulses over the sendPin and reading the state on the receivePin. When the read changes, it delivers a number as an output of the read() function.

To put it in numbers, with R = 1 and C = 0.5 => time cnst = RxC = 0.5 secs, so if you input 10V it will take 2.5 secs to fully load, and the same happes if you input 100V, or 3 mV.

Hope that helps to clarify this hardware!

The pictures are not pictures of YOUR setup but templates of what you want to do. I did understand the concept of a capacitive sensor, thank you. I still want to see pictures of YOUR setup, how your sensor looks like.

Well, actually it doesn't.

You're right that the time to load a capacitor completely depends on it's capacity and the resistor, that's because it's fully loaded when it has the same voltage as the input voltage.
It is relevant because you cannot measure the charge of the capacitor but the voltage over it. And we're not in a perfect world so things like the length of the cable between your Arduino and the sensor gets more importance the lower the voltage is (measurement errors). Long cables also has a capacity which might influence the timing differences between hand on sensor or a free sensor.