After several experiments with
touch sensors, this one works really well. One pin on the
PIC is used to create a short pulse. Any number of other
pins act as touch sensitive inputs. Here is what a snipet
of the code for 4 inputs looks like...
bsf rb,4 ;start pulse
movf rb,w ;read port b
bcf b,4 ;end pulse
andlw 0Fh ;select input bits
The 10k resistors shown seem
to work well with a 20mhz clock.
The circuit works like this...
With no additional capacitance (body contact) with the touch
sensor, the input goes high by the time the port is read by
the instruction after the one setting RB4 high. If just
a bit of capacitance is added (by touching the contact), the
input is still low when it is read.
Because there is no tactile
feedback or positive 'action' on this type of switch, it is
a good idea to do a software 'debounce' of the signal - read
it several times in a row to be sure of the state of the switches.
For the sensors themselves,
I like to use silver colored thumb tacks ($1 for box of 100)
from the local office supply. These work well on plastic
panels and can be easily soldered.