Using multiple capacitive sensors accurately

I made a ddr pad using capacitive sensors. It’s kind of like this, but with steel plates covered with fabric instead of aluminum foil, and only 4 instead of 6. They are connected to a single Arduino Leonardo, using the capsense library at, using a 1-megohm resistor for each sensor. The Arduino sends current through the resistor to measure the capacitance.

My goal is so that each sensor will accurately and immediately detect when I step on it. Most of the time, it works. The sensor will report a reading of about 0-30 at rest and 130-250 when I step on it, and I set the threshold at 100 so that works fine. But sometimes a sensor will jump to 60-100 at rest, and will sometimes go over 100 when I hover my foot over it or simply at random, resulting in false positives. Also, the readings tend to slowly increase the longer the Arduino is plugged in. I’m not sure why this happens, and I need some way to make this more reliable.

I tried making a ‘ground plane’ of aluminum foil that goes under all four sensors and has a wire to both a metal pipe and the Arduino ground. This helped alot, but the problem still remains.

I read in several places that connecting capacitive sensors to ground via a small capacitor can stabilize the readings. So I connected each sensor to a pin which I set to LOW using 220pf capacitors. This made things much worse; readings take 4 times as long, and now what happens is the reading will be 0-5, then I step on it and it jumps to 400 or so, but then I take my foot off and it goes to 200 before resetting to 0. Basically I don’t have a stable range of pressed/not pressed values.

Any ideas?

Any ideas?

squareballer: Any ideas?

The standard capsense library is rubbish.

You know what values are OK, makeyour code to reject values which are massively outside of range.

I might buy something/look into another approach if I can't get this fixed.

The thing is, it's almost perfect. Sometimes I use it for hours without problems. I just can't figure out what causes these anomalies.

fungus: You know what values are OK, make your code to reject values which are massively outside of range.

I think you misunderstand... the problem is that I don't have a consistent set of values that work. I can set it so that anything above '100' counts as a press, and maybe that will work 90% of the time. But then after using it for a while I see that one of the sensors has drifted to the point where it is always reporting at least 150 even if I leave it alone, so its always positive. So I adjust the code so anything above 160 counts as a press, and then the sensor goes back to normal, which means it never goes above ~130. So this isn't something I can fix by just adjusting the values in the code. Generally I have these errors with only one or two sensors at a time, and eventually they seem to go away on their own, only to return a few days later. I wish I knew what could cause something like this.