Touch foil

A piece of aluminum foil on a wire: the touch sensor of the CapacitiveSensor library and the Starter Kit's touchy-feely lamp.

Aliases: capacitive touch foil, CapacitiveSensor pad, touchy-feely lamp sensor. There is no chip on it. The foil is one plate of a capacitor and the room is the other, a few picofarads; a finger adds the body's capacitance, about a hundred more.

Pins

Pin What it does
FOIL The foil. Wire it to the receive pin, with a resistor of about 1 megohm to the send pin.

Reading it on an Arduino

With Paul Badger's CapacitiveSensor library, which Mokxi ships as CapacitiveSensor.h. A 1 megohm resistor goes from pin 4 to pin 2, and the foil is on pin 2:

#include <CapacitiveSensor.h>
CapacitiveSensor capSensor = CapacitiveSensor(4, 2);

void loop() {
  long value = capSensor.capacitiveSensor(30);
  digitalWrite(13, value > 100 ? HIGH : LOW);
}

The library flips the send pin and counts how long the receive pin takes to follow through the resistor. A touch makes the count several times larger.

Properties

Property What it sets
pad The foil and its lead alone, in picofarads, 10 by default.
finger What a touch adds, in picofarads, 100 by default.

While it runs

Hold the pointer on the foil to touch it.

What the model gets right

The foil is a capacitor to ground solved in the circuit's matrix, so the count the library reads is the real RC time through the resistor you chose: a larger resistor gives a larger count, and a touch multiplies it by the ratio of the capacitances.

What it does not model

A hand coming near before it touches (the real count rises as the hand approaches, which is how it senses through paper), mains hum picked up by the body, and the board's ground not being earth.

Common mistakes

Leaving out the resistor, or using a small one: the receive pin follows at once and the count stays near zero.

See it in action

Touch lamp is the Starter Kit project. Open it at /templates.