Arduino Capacitive Switches

In this experiment I am going to use my first outside library to add Capacitive Sensing to the Arduino as demonstrated on You Tube.   This is the same technique used by most modern touch screen such as the iPad and iPhone and this feature is brought to the Arduino via the CapSense library written by Paul Badger.

Installing the CapSense library.

To install the library it needs to be downloaded from the playground and placed into a folder called libraries inside your Ardiuno Sketchbook (the place you store all your Ardiuno projects).

Restart the Arduino IDE, open the project you are working on and then use sketch > import library to import the CapSense library into your sketch.  At the most simple level you need to create a new CapSense object where pin 7 represents the source and pin 8 the signal lead.

CapSense   cs_grey = CapSense(7,8);

and then inside the loop function you can call the CapSense object and test the current value.  The value returned is in an arbitrary unit which you can test against and of course respond to.

long total1 = cs1over7_8.capSense(30);

For more information you should refer to the documentation written by Paul Badger.

Creating the Switches

The switches can be created using a number of different techniques including a paper clip and a piece of wire.

The circuit should look something like:

The recommended resistor value is anything from 50kΩ to 50mΩ with 10mΩ given as a starting point.  Personally, I found that too low and need to pop a couple in series to give 20mΩ.

The following video shows the switches under operation without the stabilising capacitors suggested which I need to order.

/**** UPDATE ****/

So after a slight delay due to distractions I have added a stabilising capacitor to a single touch switch.  I’ve also changed the design of the switch as shown below.  In version 2 I have been able to glue some foil between the wood and paper.

In actual fact I found that the sensitivity of the switch varies greatly depending on whats around it. Three switches was less sensitive than a single one but once I had mounted the camera on the edge of the board the switch became so super sensitive it was more of a proximity sensor than touch sensitive switch!

Anyway, experiment over – next!

Here is the code I used for those that asked.  You will need to remove the .txt file extension. (12/01/2013)

6 Comments on “Arduino Capacitive Switches

  1. do you have a example of the code that you used to turn on de leds when you touch the paperclips?
    thanks

    • I’ve added two scripts to the post above but you will need to grab the library too.

  2. I belive that the scheme from section “The circuit should look something like:” is wrong. All 3 sense pins will see the same voltage. The 3 resistor are conected in parallel to the same point.

  3. I agree with Adrian the 190pF caps should not be connected together. Each should be connected to its corresonding receive pin.

    • Quite possibly, I’m not an electrics expert and am only finding my way with these experiments or could have easily made a mistake drawing up the circuit. I’ll try and find a moment to double check.

  4. Hi , I am currently doing the same project.. Do you know how can i download the arbitrary unit obtained from the capacitor sensor and make it into graph ?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.