Practical uses of Capacitors in Arduino projects?

Hi guys,

I'm moving my first steps with Arduino. I have a base workshop kit with come with a lot of different capacitors. I read about what are they usually used, anyway I still don't see a practical use scenario for them on simple arduino projects..

Would you suggest example of usages of capacitors in Arduino projects? Both link than explainations.

Thanks,

Fabio Varesano

You can use them to generate analogue voltages under program control with the analogWrite() function. I'm sure this is covered in a manual somewhere but it will only need a single resistor and one of your capacitors.

Components like capacitors and resistors are called passive components and have nearly zero usage by themselves. They are needed as part of a circuit designed to accomplish some task. So one normally doesn't start with a idea to utilize a cap, but rather finds or designs a higher level circuit that may or may not require a cap.

Lefty

They sure do stop relays from going crazy

Physiotherapy for relays that's a new one on me.

Actually a capacitor probably saved my future in hobby eletronics.

I had a basic relay opening/closing to swap between 2 leds. My wife came over and pressed the button and she thought she got shocked and said if i didn't fix it she would take my toys away.

Added a capacitor and it fixed it. She didn't get shocked, the relay fired so quickly over and over it felt like it.

You could always swap you wife.

Thanks guys for the replies. Do you remember practical projects here on Arduino website or everywhere on the web with cool things which uses (also as side components) capacitors?

The problem is: I do know what a capacitor does. The theory around it. Still I don't see how can I use in my Arduino projects, even if as a side component. Instead I always see lot of usages for eg resistors, buttons, transistors, etc.. Capacitors are still kind of vodoo to me.

Graynomad and tehjrow suggested two common uses for capacitors in Arduino projects:

  1. electronically debounce a switch (as opposed to doing it in software like here: http://www.arduino.cc/en/Tutorial/Debounce

  2. generate analog voltages using analogWrite(). You may have read that Arduino's "analog" output is really PWM, consisting of a timed mix of 100% and 0% voltages, with nothing in between. That's find for LEDs and hobby motors, but sometimes that won't work. For instance, if you wanted to play a nice smooth sine wave tone through a speaker, you'd need one or more capacitors to convert the square wave from the Arduino into a sine wave for the speaker. See here for more: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1268237950/12

devices like shift registers and counters put a bunch of noise on the power lines, you can use small capacitors to filter that noise out before it hits the chip (or else it may be erratic)

I've spent a few mins thinking about your question. If you want to really learn something about capacitors rather then just utilize them I would suggest a project that is very useful as well as educational. Build a circuit and write a program such that the Arduino can read the capacitance value of a capacitor you wire to the 'test terminals'. You would use a digital output pin set to HIGH to start and time a constant voltage charging a capacitor through a series resistors. you would wire the resistor/capacitor junction to a Arduino analog input pin such that you can measure the caps voltage charge at any given time in the testing cycle. You would then set the output pin to LOW to discharge the cap prior to starting another measurement cycle.

You might use several different digital outputs using different value series resistor wired to the cap and then ground. This would allow for larger capacitance measurement range. Turning on only one digital output pin at a time (the others need to be turned into digital inputs pins to not effect the charge time).

Anyway do a search on capacitor R/C time constant and then start thinking on how you can use software to time how long it takes the cap to charge to a certain value voltage and how you calculate the resulting capacitance and how you may display the results.

I think you would find it both challenging and educational as well as ending up with a practical capacitor measurement instrument.

Lefty