I've built some simple capacitors to use as pressure pads on the stairs at home - the aim is to light the stairs up as you go up them - here it is in action. But I'm getting weird readings form them, but only when connected one way round.
I've built them by sticking a piece of kitchen foil to each side of a piece of card, then sticking a stripped wire to either side. They then attach to a small circuit board via a molex KK connector ("SENSOR"), schematic below.
DATA_IN and DATA_OUT ports connect to other similar circuit boards. RA0 outputs data in serial format at 57600 baud. RA2 connects to RA1 of the "downstream" board and allows for the devices to self-enumerate and manage usage of the serial bus.
Power is provided by a battery and data is read through a rasberry pi via an optocoupler - so no electrical connection outside of this system.
The firmware on the PIC works by first setting RA4 low for a millisecond to drain the capacitor. RA4 then becomes an input and is attached to a comparator which compares against an internal voltage reference (4/5 Vdd).RA5 now goes high, and we start a timer and measure how long it takes for the voltage to reach the reference. When weight is applied to the sensor, the card compresses and the capacitance increases - and takes longer to charge up.
Most of them work normally, and take about 800 uS to charge up to 4/5 Vdd. But some give really bizarre readings, fluctuating between about 30uS up to 4000uS to charge - and it changes on every single reading. Even weirder, if I take the connector attached to the "SENSOR" header on the board and reverse the polarity of the sensor - it starts working normally.
So in a sense, I have a solution to the problem - reverse the polarity of the sensors - but this is unsatisfactory as I have no idea why these apparently symmetrical sensors should behave so differently depending on which way round they are attached. Why is this happening?