Fail to compile CapacitiveSensorSketch

I am using an Arduino Leonardo. I have the IDE installed and can run the blink example sketch. So the board and IDE seem to be working. I want to run capacitive sensor so I downloaded and unziped to libraries folder the capacitive library.

I get the following errors when it compiles:

CapacitiveSensorSketch:12: error: ‘CapacitiveSensor’ does not name a type
CapacitiveSensorSketch:13: error: ‘CapacitiveSensor’ does not name a type
CapacitiveSensorSketch:14: error: ‘CapacitiveSensor’ does not name a type
CapacitiveSensorSketch.pde: In function ‘void setup()’:
CapacitiveSensorSketch:18: error: ‘cs_4_2’ was not declared in this scope
CapacitiveSensorSketch.pde: In function ‘void loop()’:
CapacitiveSensorSketch:25: error: ‘cs_4_2’ was not declared in this scope
CapacitiveSensorSketch:26: error: ‘cs_4_6’ was not declared in this scope
CapacitiveSensorSketch:27: error: ‘cs_4_8’ was not declared in this scope

I think the problem is it can not find the include file as sketch does not show that in orange. see below

#include <CapacitiveSensor.h>


  • CapitiveSense Library Demo Sketch
  • Paul Badger 2008
  • Uses a high value resistor e.g. 10M between send pin and receive pin
  • Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
  • Receive pin is the sensor pin - try different amounts of foil/metal on this pin

I have looked at example on web but can not figure what I am doing wrong.

Any ideas?

You need to unzip the library in the right place. It's important to know which O.S. you use (windows, linux, mac) ? Standard library (from arduino team like servo are on my windows pc:


User library under library in your project folder. On my windows pc:


Normally this directory is under "\Documents and settings" folder.

On linux and mac you need to pay attention to upper/lower case of directory names.

HI AFR2013,

Have you got some solutions for your compilation problem ?



I had the same issue beacause I extracted directly under my librairies folder but IN THE ZIP FILE you have to take the folder under the folder named libraries and place it in your librairies folder (e.g. ...Documents\Arduino\libraries).