# Capacitive Sensing

Is there a way that I can make an Arduino or other Micro-controller detect a change in capacitance?

I'm thinking of having a screen on my door that only turns on when you touch the metal door handle.

Yes.

Simplest way would be to use a high value resistor (1-10M) and follow the instructions on this old arduino forum post: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1171076259

Here is a tutorial http://www.nerdkits.com/videos/halloween_capacitive_touch_sensor/

The actual sensor used to detect the presence of a hand in explained in detail in the video, but here is an overview. Our sensor operates on the same principle that a capacitive touch sensor works on your laptop touchpad. These capacitive touch sensors work on the premise that humans are mostly water. When you get near an electric field you alter the capacitance enough to be noticed by the sensor.

In our system we set up an RC circuit with a capacitor and a resistor in parallel. We use the MCU to charge capacitor up to 5V (a digital high voltage). Then we turn the pin into an input pin, which essentially disconnects that node. This allows the capacitor to discharge through the resistor. The amount of time it takes the capacitor to discharge will be related to the resistor value times the capacitance. We pick a resistor value large enough that the RC time constant is long enough for us to measure with the MCU. In this case 100K ohms worked great. The sensor in this case is two sheets of aluminum foil, one connected to the MCU pin, and one connected to GND. These two sheets create a capacitor that our MCU is charging and discharging. When your hands move between the two sheets, it alters the electric field, and therefore the capacitance of our tin foil contraption. The capacitor therefore takes longer to discharge, and that is detected by the code on our microcontroller!

One of the best ways that I've found to measure capacitance is to use an RC circuit. Use a digital I/O port on a microprocessor to charge and discharge the capacitive sensor through a fixed resistor. Start a timer when you begin the charge/discharge cycle. Then use a comparator to detect when the capacitor has fully charged/discharged. Stop the timer when the comparator trips. The value stored in the timer can then be used to calculate the capacitance of the sensor.

Not an Arduino specific answer, but Microchip have an explanation of one way to do it on the PIC - which would possibly work on an AVR

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en545264

Only concern with these methods is lack of protection from static discharge

A capacitive touch sensor can be done without additional hardware. The trick is to enable the internal pull-up of a digital pin, and count the CPU cycles it takes to pull the pin up.

Code and explanation: http://playground.arduino.cc/Code/CapacitiveSensor

I prefer taking the analog part of the job away from the microntroller by using the capacitor under test as part of an oscillator and then using the controller to measure puse width. It is an extra part, but I've had better results this way.