Go Down

Topic: Capacitive Sensors being inconsistent (Read 944 times) previous topic - next topic

agmui

I am working on a project where I try to have 4 foil pads that press a key on my keyboard. This is kind of like those Arduino pianos. What I did is have the 4 pads set up on a breadboard connected to my Arduino. Then my Arduino is connected to my computer and is sending numbers thought serial. I have a python program running on my computer to create keyboard presses. The pads I made by cutting out small squares of tin foil from a tray and adding a small strip of copper tape on the back so I could solder wires to it. Also, the resistor I used was 10M Ohm.

The problem I believe is in the foil pads because they are very inconsistent because when I was testing the values of the pads they would change when more than one pad was being touched. So for example when I was touching one pad it would normally read 24 and while not touching it the Arduino would read 235. However, when would touch another pad the reading for the pad I am currently touching would go up. What ends up happening is that the highest reading of the pad I am touching would reach what it would be at rest. This makes it hard for me to tune the code because when running it the Arduino thinks that one pad is not being touched. One other side effect is that originally the readings of the pads being touched and not touched would be 24 and 235. But after touching more than one pad the readings may or may not jump up to 78 and 245. This would mess up the code because it would be hard to tune because I could not tell what the new values were. Another quirk was if I were to record the values of one test they may or may not change when  I would test it again. One last symptom was that when I was testing the readings would randomly go to zero or low value and I would have to touch it again to have it go back to its original untouched value. This would happen for all the pads, not just one and all at the same time. I don't know why this happens but I think it is because I haven't touched the pads for a small period of time. I tried to solve the problem by having the Arduino sense whenever there was a big difference in the readings but that also was not accurate.
Code: [Select]
/*

*/
#include <CapacitiveSensor.h>


CapacitiveSensor   cs_4_2 = CapacitiveSensor(3,2);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor   cs_10_6 = CapacitiveSensor(5,4);        // 10M resistor between pins 10 & 6, pin 6 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_12_8 = CapacitiveSensor(7,6);        // 10M resistor between pins 12 & 8, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_13_11 = CapacitiveSensor(9,8);

int old1 = 10;
int old2 = 10;
int old3 = 10;
int old4 = 10;

int w = 1;
int x = 2;
int y = 3;
int z = 4;

void setup() {
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   cs_10_6.set_CS_AutocaL_Millis(0xFFFFFFFF);
   cs_12_8.set_CS_AutocaL_Millis(0xFFFFFFFF);
   cs_13_11.set_CS_AutocaL_Millis(0xFFFFFFFF); 
   Serial.begin(9600);
   delay(1);
}
void loop() {
  while (!Serial.available()) {
   
    char buffer[10];
   
    long start = millis();
    long total1 =  cs_4_2.capacitiveSensor(30);
    long total2 =  cs_10_6.capacitiveSensor(30);
    long total3 =  cs_12_8.capacitiveSensor(30);
    long total4 =  cs_13_11.capacitiveSensor(30);
    /*
    if (abs(total2 - old2) > 70){
      x = x*-1;
    } else {
      x = x;
    }
    */
   
    if (total1 > 300){
       w = 1;
    }
    if (total1 < 300) {
       w = 2;
    }
   
    if (total2 > 25){
       x = 3;
    }
    if (total2 < 25) {
       x = 4;
    }
   
    if (total3 > 20){
       y = 5;
    }
    if (total3 < 20) {
       y = 6;
    }
   
    if (total4 > 29){
       z = 7;
    }
    if (total4 < 29) {
       z = 8;
    }
   
     old1 = total1;
     old2 = total2;
     old3 = total3;
     old4 = total4;
    sprintf(buffer,"%1d%1d%1d%1d",w,x,y,z);
    Serial.print(total2);
    //Serial.write(buffer);
    Serial.print("\n");
    //delay(19);
  }
   
}

pylon

We're talking about such small capacitances that the more or less parallel wires also have a capacitance and if the capacitance of the other wire changes, the overall capacitance change too.

The common resistor for capacitive touch sensors is 500kΩ to 1MΩ. Your's is substantially bigger, so these effect sum up.

agmui

Ok sorry for taking so long or reply but the resistor took along time to come. There is a new problem is that When I press on one pad it works fine but pressing on another makes the Arduino think all the pads are being touched. Also in rare instances, a pad works perfectly fine with nothing wrong.

pylon

Did you change the circuit?


Quote
When I press on one pad it works fine but pressing on another makes the Arduino think all the pads are being touched.
Which pad works, which pad does result in all inputs triggering?

agmui

I used the same circuit but changed all the resistors to 1M. Also, all the pads like randomly worked and stopped working. Like when I would first read the inputs of one pad they would work for like 10 sec then I would go do something for like 5 sec and when I came back they just stopped working. That happened to all the pads

wvmarle

Are you powering from battery or connected to a computer which in turn is connected to a grounded mains outlet? Proper grounding is essential to make this capacitive touch work.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

agmui

I just connected the circuit to my Arduino which is only connected to the computer. I don't use any outside power source. Also when you mean proper grounding do you mean to connect all the resistors to ground and an individual input pin.

wvmarle

You need a stable, true ground reference - as in earth ground. Arduino via USB to computer to grounded outlet should offer this.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

agmui

So then my schematic above should work when I change the resistors from 10M to 1M.

wvmarle

Well, one way to find out!

For more reliable and easier touch sensors look into the TTP223 based touch modules. Dirt cheap, too. Haven't tried connecting it to a home made touch pad, though that should work just fine.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

agmui

That is my question, I already tested that set up I mentioned above on the 21st and the Arduino reads it in a  weird way. If you want more details about what is happening I can tell you.

Go Up