You could try using the MPR121 capacitive touch sensitive controller as here.
I have been experimenting with using an Arduino analogue input directly for a touch switch. I am sceptical whether most touch switches are genuinely detecting change in capacitance or just detecting pick up of electrical noise, mainly hum from the electricity supply frequency (i.e. 50 or 60 Hz). Anyone using an oscilloscope will have noticed how much signal is picked up if you touch its probe. I am therefore aiming to detect the presence of a finger by detecting an increase in electrical noise, not by detecting change of capacitance.
I have been using a smallish sheet of metal covered by an paper label and adhesive plastic film (as available from stationers). There is therefore no contact with the finger, only capacitive coupling through the paper and film. The metal is connected directly to the A2 pin of my Arduino Micro. The Arduino is powered by 5 volts (supplied by USB) and the metal is biased by a 1 MΩ resistor connected from A2 to the 3.3V pin. I am investigating whether a 1.8nF capacitor across this resistor helps.
With the metal biased to 3.3V, the value read by the Arduino's analogue-to-digital convertor is expected to be close to 675 in the absence of electrical noise. My code starts with 675 but uses a modified moving average calculation to get closer to the actual average.
The electrical noise 'power' is derived by calculating the short-term average of the square of the deviation from the average voltage. It is expected that using the square of the deviation will be better for determining whether a finger is touching the insulated metal sheet than using the modulus of the deviation. Some other mathematical function could be used.
Using the short-term average of deviation squared, the code currently interprets over 120 as being a touch and under 60 as being a release. I am thinking of making these threshold values adaptive. If you try the code below, you may need to modify the two thresholds.
My code will send data over the USB but currently only lights the on-board LED when a finger is detected.
I require four touch keys so will use four analogue inputs. If you need more keys than available analogue inputs, you could try multiplexing using one or more analogue gates such as the CMOS 4067.
int adc ; // value from ADC
float average=675 ; // initial moving average ADC value based on 3.3V
int nAverage = 100 ; // n in modified moving average calculation of ADC reading
float deviation ; // deviation from average
float avDeviationSq = 0 ; // deviation squared and averaged
int nDeviation = 10 ; // n in modified moving average calculation of deviation squared
void setup() {
pinMode(13, OUTPUT); // for on-board LED
delay(2000); // allow time for moving average to settle, probably unnecessary
}
void loop() {
adc = analogRead(A2) ; // using A2 pin
average = ( average * (nAverage - 1) + adc ) / nAverage; // compute modified moving average of ADC value
deviation = adc - average ;
avDeviationSq = ( avDeviationSq * (nDeviation - 1) + deviation * deviation) / nDeviation ; // compute modified moving average of deviation squared
if (avDeviationSq > 120) digitalWrite(13, HIGH); // finger touching threshold
if (avDeviationSq < 60 ) digitalWrite(13, LOW ); // finger release threshold
delay(10); // loop delay (ms)
}