There are at least four ways to implement a capacitive touch sensor:
A standalone breakout board with a touch pad, electronics, and an output that will indicate when the pad is touched.
This method does not need a microprocessor or any coding. Examples are: https://www.adafruit.com/product/1374 ... for momentary touch action
and https://www.adafruit.com/product/1375 ... for toggle action
------------------------------
A native sensor using just arduino inputs and internal pull-up resistors.
"You can create a touch-sensitive input on any of the Arduino's pins.
It requires no special hardware, nevertheless a capacitor of 1nF is recommended in line with the pin to decouple 50Hz noises.
Connect a wire or some metallic plate to a pin.
The code works by setting the pin to ground, turning on the internal pull-up resistor, and measuring the time it takes for the pin to return to the HIGH state.
If untouched, readCapacitivePin returns a low-ish value e.g. "1"; when touched it rises to about 5.
By adding some comparison with a threshold you can make it a boolean key input."
Code from this link is transcribed into my program: capSenseRef-04-00
Two pins are used, a send pin and a receive pin. A large-value resistor is connected between them.
A sense/touch pad is connected to the receive pin. The sense pad may be connected directly to the receive pin, or a 1k or higher resistor can be connected in series to protect from ESD.
R, the "large-value resistor", can be from 100K to 50M. Smaller values give faster response. Larger values give more sensitivity, allowing triggering from a distance, ie. not actually touching the sensor pad.
A clever implementation is to put a piece of paper or other slightly deformable insulator on the pad, then adjust the resistor appropriately, with the result that the sensor will act as a defacto pressure sensor.. Coding to return an analog value requires using methods in the library. (see link ...)
"Also experiment with small capacitors (100 pF - .01 uF) from sense pin to ground. They improve stability of the sensor. "
In my tests:
100K wouldn't trigger at all
10M worked well, even through a layer of stretch plastic film
20M worked through film (with 1" square tinfoil pad) without even touching. It started flickering when finger was about an inch away, and was on solid when about 1/8" away.
"Multiple sensors can share a single send pin, but each must have its own receive pin." ... not sure how this works...
------------------------------
Some Teensy models with on-chip hardware for capacitive sensing and do not need this library. Simply use touchRead(pin).