What is a capacitor?
In a way, a capacitor is a little like a battery. Although they work in completely different ways, capacitors and batteries both store electrical energy. Inside the battery, chemical reactions produce electrons on one terminal and absorb electrons on the other terminal. A capacitor is much simpler than a battery, as it can't produce new electrons -- it only stores them. Inside the capacitor, the terminals connect to two metal plates separated by a non-conducting substance, or dielectric. You can easily make a capacitor from two pieces of aluminum foil and a piece of paper. It won't be a particularly good capacitor in terms of its storage capacity, but it will work. In theory, the dielectric can be any non-conductive substance. However, for practical applications, specific materials are used that best suit the capacitor's function. Mica, ceramic, cellulose, porcelain, Mylar, Teflon and even air are some of the non-conductive materials used. The dielectric dictates what kind of capacitor it is and for what it is best suited. Depending on the size and type of dielectric, some capacitors are better for high frequency uses, while some are better for high voltage applications. Capacitors can be manufactured to serve any purpose, from the smallest plastic capacitor in your calculator, to an ultra capacitor that can power a commuter bus. NASA uses glass capacitors to help wake up the space shuttle's circuitry and help deploy space probes
When you connect a capacitor to a battery, here's what happens:
* The plate on the capacitor that attaches to the negative terminal of the battery accepts electrons that the battery is producing.
* The plate on the capacitor that attaches to the positive terminal of the battery loses electrons to the battery.
Once it's charged, the capacitor has the same voltage as the battery (1.5 volts on the battery means 1.5 volts on the capacitor). For a small capacitor, the capacity is small. But large capacitors can hold quite a bit of charge. You can find capacitors as big as soda cans that hold enough charge to light a flashlight bulb for a minute or more.
Even nature shows the capacitor at work in the form of lightning. One plate is the cloud, the other plate is the ground and the lightning is the charge releasing between these two "plates." Obviously, in a capacitor that large, you can hold a huge amount of charge!
Here you have a battery, a light bulb and a capacitor. If the capacitor is pretty big, what you will notice is that, when you connect the battery, the light bulb will light up as current flows from the battery to the capacitor to charge it up. The bulb will get progressively dimmer and finally go out once the capacitor reaches its capacity. If you then remove the battery and replace it with a wire, current will flow from one plate of the capacitor to the other. The bulb will light initially and then dim as the capacitor discharges, until it is completely out.
Like a Water Tower
One way to visualize the action of a capacitor is to imagine it as a water tower hooked to a pipe. A water tower "stores" water pressure -- when the water system pumps produce more water than a town needs, the excess is stored in the water tower. Then, at times of high demand, the excess water flows out of the tower to keep the pressure up. A capacitor stores electrons in the same way and can then release them later.
Farad
A capacitor's storage potential, or capacitance, is measured in units called farads. A 1-farad capacitor can store one coulomb (coo-lomb) of charge at 1 volt. A coulomb is 6.25e18 (6.25 * 10^18, or 6.25 billion billion) electrons. One amp represents a rate of electron flow of 1 coulomb of electrons per second, so a 1-farad capacitor can hold 1 amp-second of electrons at 1 volt.
A 1-farad capacitor would typically be pretty big. It might be as big as a can of tuna or a 1-liter soda bottle, depending on the voltage it can handle. For this reason, capacitors are typically measured in microfarads (millionths of a farad).
Applications
The difference between a capacitor and a battery is that a capacitor can dump its entire charge in a tiny fraction of a second, where a battery would take minutes to completely discharge. That's why the electronic flash on a camera uses a capacitor -- the battery charges up the flash's capacitor over several seconds, and then the capacitor dumps the full charge into the flash tube almost instantly. This can make a large, charged capacitor extremely dangerous -- flash units and TVs have warnings about opening them up for this reason. They contain big capacitors that can, potentially, kill you with the charge they contain.
Capacitors are used in several different ways in electronic circuits:
* Sometimes, capacitors are used to store charge for high-speed use. That's what a flash does. Big lasers use this technique as well to get very bright, instantaneous flashes.
* Capacitors can also eliminate ripples. If a line carrying DC voltage has ripples or spikes in it, a big capacitor can even out the voltage by absorbing the peaks and filling in the valleys.
* A capacitor can block DC voltage. If you hook a small capacitor to a battery, then no current will flow between the poles of the battery once the capacitor charges. However, any alternating current (AC) signal flows through a capacitor unimpeded. That's because the capacitor will charge and discharge as the alternating current fluctuates, making it appear that the alternating current is flowing.
Capacitive Touch Screens
One of the more futuristic applications of capacitors is the capacitive touch screen. These are glass screens that have a very thin, transparent metallic coating. A built-in electrode pattern charges the screen so when touched, a current is drawn to the finger and creates a voltage drop. This exact location of the voltage drop is picked up by a controller and transmitted to a computer. These touch screens are commonly found in interactive building directories and more recently in Apple's iPhone.
Capacitance Background information and image from howstuffworks.com
Capacitance and Arduino
Arduino Pins can very easily be wired to create a simple capacitance reliant touch sensor using a resistor and a piece of wire with a bit of foil attached as illustrated in the following diagram.
image from Capsense Arduino Library
Simple Capacitance Code
// CapSense.pde
// Paul Badger 2007
int i;
unsigned int x, y;
float accum, fout, fval = .07; // these are variables for a simple low-pass (smoothing) filter - fval of 1 = no filter - .001 = max filter
int ledPin = 5; // select the pin for the LED
float nonTouched, store = 0;
void setup() {
Serial.begin(9600);
//DDRB=B101; // DDR is the pin direction register - governs inputs and outputs- 1's are outputs
// Arduino pin 8 output, pin 9 input, pin 10 output for "guard pin"
// preceding line is equivalent to three lines below
pinMode(8, OUTPUT); // output pin
pinMode(9, INPUT); // input pin
pinMode(10, OUTPUT); // guard pin
digitalWrite(10, LOW); //could also be HIGH - don't use this pin for changing output though
pinMode(5, OUTPUT);
analogWrite(ledPin,255);
delay(10);
analogWrite(ledPin,0);
}
void loop() {
y = 0; // clear out variables
x = 0;
for (i=0; i < 4 ; i++ ){ // do it four times to build up an average - not really neccessary but takes out some jitter
// LOW-to-HIGH transition
//PORTB = PORTB | 1; // Same as line below - shows programmer chops but doesn't really buy any more speed
digitalWrite(8, HIGH);
// output pin is PortB0 (Arduino 8), sensor pin is PortB1 (Arduinio 9)
//while ((PINB & B10) != B10 ) { // while the sense pin is not high
while (digitalRead(9) != 1) { // same as above port manipulation above - only 20 times slower!
x++;
}
delay(1);
// HIGH-to-LOW transition
// PORTB = PORTB & 0xFE; // Same as line below - these shows programmer chops but doesn't really buy any more speed
digitalWrite(8, LOW);
//while((PINB & B10) != 0 ){ // while pin is not low -- same as below only 20 times faster
while(digitalRead(9) != 0 ) { // same as above port manipulation - only 20 times slower!
y++;
}
delay(1);
}
fout = (fval * (float)x) + ((1-fval) * accum); // Easy smoothing filter "fval" determines amount of new data in fout
accum = fout;
store++;
if (store<50) {
nonTouched = fout;
}
if (store>50){
store = 50;
}
Serial.print((long)x, DEC); // raw data - Low to High
Serial.print( " ");
Serial.print((long)y, DEC); // raw data - High to Low
Serial.print( " ");
Serial.print( (long)fout, DEC); // Smoothed Low to High
Serial.print( " ");
Serial.println( (long)nonTouched, DEC); // Smoothed Low to High
if (fout>nonTouched+3){
analogWrite(ledPin,255);
}
else{
analogWrite(ledPin,0);
}
}
CapSense Arduino Library
CapSense is an external code library for the Arduino environment that contains two functions for using the Arduino to sense capacitance.
long capSense(uint8_t sPin, uint8_t rPin, int samples)
- sPin - send pin, any 'duino pin. This is the sending pin.
- rPin - receive pin, any 'duino pin. This is the sensor, connect a piece of wire and or foil to this pin.
- samples - number of times to sample. Use this to take out jitter, at the expense of slower operation.
- the function returns capacitance at rpin in arbitrary units, a long, zero referenced
This function subtracts the "not-touched" baseline reading from the result, yielding the "added" capacitance that has been sensed. It automatically resets this baseline function at the count of CAPSENSERESET times through the loop, defined in the header file as 0xFFFFL (65535). When reset happens, a sensed hand will read as zero then reset properly as the sensor sees an "unsensed" condition. This might cause a glitch in behavior so you probably don't want this to happen too often.
long capSenseRaw(uint8_t sPin, uint8_t rPin, int samples)
sPin - send pin, any 'duino pin. This is the sending pin.
- rPin - receive pin, any 'duino pin. This is the sensor, connect a piece of wire and or foil to this pin, experiment.
- samples - number of times to sample. Use this to take out jitter, at the expense of slower operation.
- the function returns raw capacitance at rpin in arbitrary units, a long
The function capSenseRaw just reports the raw data without subtracting the baseline reading. capSense calls capSenseRaw for its data.
Download the CapSense and view code examples
Other Solutions for Touch Sensing with Arduino
There are a number of other ways to create touch sensors for Arduino projects
Conductive Foam
A simple analog pressure sensor can be made by sandwiching a piece of conductive foam between two conductive surfaces.
DIY Pressure Sensor Instructable
Soft Switches
Momentary soft touch switches can be created using just about any conductive material with some padding in between the contacts.
Ribbon Controllers
photo from MAKE: Blog
Electromagnetic tape from audio cassettes or VHS tapes can also be used as an analog touch sensor. Running a finger along the tape creates a voltage divider and outputs analog values.
How to build a Ribbon Controller
Ribbon controller + Arduino for head sleep position tracking
Human body as circuit
The person touching the object can also be used as a circuitry component. The human body is conductive but has natural variable resistance depending on temperature and perspiration. Two examples of human contact completing a circuit to control audio and video:
You can actually build a capacitor from common components as indicated in this article.
For high voltage caps, a proper dielectric must be used. See my technology blog at www.pocketmagic.net to learn how to build a high voltage capacitor.
Posted by: Radu | 08/29/2010 at 03:21 PM