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.
/*
*/
#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);
}
}