Simple touch sensors with the Arduino CapSense library

Ever thought of using touch sensors on your projects but didn’t because it would be too much work? [Paul Stoffregen] proves that it can be pretty easy if you use the CapSense library for Arduino. Here he’s created three touch sensors, connecting them to the Teensy microcontroller with two resistors each. The larger resistor (looks like 4.7 megaohms here) sends a signal through the copper pad which is read by the secondary pin. Here that pin is protected from electrostatic discharge with the 1k resistors. The microcontroller takes a reading by measuring how long it takes the voltage to change on the input pin.

Since the CapSense library takes care of the timing involved in these readings, all you have to do is decide how your program will react to the numbers that are coming in. In the video after the break [Paul] is echoing the timing figures back through the serial monitor to get an idea of what the data looks like. He experiments with touching the copper directly, and touching it through a piece of clear tape.

We’ve seen the CapSense library at work before in this interactive exhibit piece.


  1. BrainSlugs83 says:

    That’s really cool! It seems like this kind of thing could be done with a regular AVR and some clever interrupt coding.

  2. insapio says:

    Very nice, I saw this in the teensy example sketches, but this is a very nice implementation. I remember seeing what was basically a 4 wire touchpad made with either copper clad or aluminium foil, anyone know where that project it? I believe it was featured on HaD…

  3. Sam says:

    I just implemented the same thing but using only using one pin per sensor for a “star trek” door entry button a couple weeks ago. Useful if you are low on I/O pins. Same basic idea except it quickly cycles the pin between an input and an output so you don’t need separate send and receive pins.

    • Daid says:

      You’re measuring charge times, but you might be better off by measuring discharge times after disabling the pull-up? A difference of 1 to 5 isn’t very big.

      • Sam says:

        My hardware is slightly different than the example and mine sits at about 2 or 3 and goes up to 14 or 15 with direct touch and about 9 with a piece of tape over it. Found I have plenty of difference for state change detection.

        Beware, ESD protection matters! I killed the first pin I was testing with even sitting on my ESD mat.

  4. Eirinn says:

    A very nice project, but it would be more useful if you didn’t have to directly touch the strip. In most applicable cases there will be at least a millimeter of glass/plastic between the metal strip and the finger.

    • Paul says:

      Hi, Paul here… the guy who made this little video.

      Proximity effect does work. Obviously you don’t get a really strong change like direct touch or touch through a thin piece of tape.

      I had actually planned another 10-15 seconds to demo proximity effect. It was in my script when I recorded the voice over. But when I filmed the demos, doing 2 takes of each (and fumbling with the screen recording program, camera, lighting, etc), somehow I missed that both times. I had written the entire script, but this seemed like such a simple little project that I didn’t make a written shot list for the actual filming (and screncast).

      The truth is I’m still not very experienced with shooting and editing. When I edited, I realized I had missed that shot. I didn’t use that audio and took it out of the project… rather than setting the whole thing up again.

      I had also _really_ wanted to do animated graphics overlay, instead of those static arrows and circles… especially some sort of animated graphic depicting the current flow and gradual voltage change. But animated graphics in the editing is far beyond my skills. Hopefully someday….

      I’m still learning my way around FCPX and shooting better video. This was my first attempt at a number of FCPX features, like doing a picture-on-picture overlay to show the serial monitor while touching the sensors. I’m slowly getting better. Next time I’ll definitely make a written shot list, so I don’t forget something and have to edit it out.

  5. Wouter Van Vlaenderen says:

    Has anyone had success with implementing a slider or scroll wheel using the CapSense library and the Arduino framework?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 96,614 other followers