Capacitive touch surface fine tuning

Hello everyone,
I’m new to the forums and I’m not sure this is the right thread for my question, but anyways:
I’ve built a kind of “infinity mirror”, which has an aluminium frame. I thought it would be nice to use the frame as a capacitive touch switch to turn the LED strips in the mirror on and off. So I used the Capsense library, added the appropriate resistors, made a voltage divider, and connected everything up between A1 and GND. Then I plugged in my USB cable and the 12V battery that will power the lights and the Arduino itself, and read out the values coming from the surface through the serial monitor, and set the appropriate values for turning the lights on or off. It worked like a charm, until I disconnected the USB cable.
As I figured by letting an LED that I had on my board for battery level indication flicker for different values of the sensor, and I figured I get vastly different values when using only 12V or only 5V, as I get when I have both 12V and the USB connected.

Anyone has an idea why?
Thanks, Tamas

I don't have any good clue myself but have you re-uploaded the code? If that solves the case you may want to search for a line of code writing outside of an array limit.
By the way, a schematic or some code would help other members to find the problem.

It worked like a charm, until I disconnected the USB cable.

Yes that is common.

Nothing to do with the actual USB power but disconnecting it changes the size, shape and capacitave coupling of the ground. The Capsense library is quite crude and is more of a demonstration than something that can be used reliably in a project. You are measuring the capacitance of your sensor and ground, you whip away that ground and the setup becomes much more less stable and sensitive.

Solutions? You could try adding a large ground plane to the system, or you could use a capacitave sensing chip to do the sensingas they use better methods than the simple charge up and note the discharge time that the Capsense library uses.

Grumpy_Mike:
Yes that is common.

Nothing to do with the actual USB power but disconnecting it changes the size, shape and capacitave coupling of the ground. The Capsense library is quite crude and is more of a demonstration than something that can be used reliably in a project. You are measuring the capacitance of your sensor and ground, you whip away that ground and the setup becomes much more less stable and sensitive.

Solutions? You could try adding a large ground plane to the system, or you could use a capacitave sensing chip to do the sensingas they use better methods than the simple charge up and note the discharge time that the Capsense library uses.

That makes sense!
I will experiment a bit with grounding the whole thing, but I will probably fall back to using a sensor anyways, as this method seems pretty finicky to me.
Thanks for the answer!

Yup - grounding is the usual issue.

Look into ready-made touch sensors such as TTP223 based ones. They're independent of a proper ground reference.

wvmarle:
Look into ready-made touch sensors such as TTP223 based ones. They're independent of a proper ground reference.

Yeah, I already ordered a few breakout boards, and will probably be my final choice!