Touchy Feely Lamp

Hello.

I'm stuck on a project in the Arduino Projects Book. Here is my code:

#include <CapacitiveSensor.h>
CapacitiveSensor capSensor = CapacitiveSensor(4,2);

int threshold = 1000;
const int ledPin = 12;

void setup () {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop() {
long sensorValue = capSensor.capacitiveSensor(30);
Serial.println(sensorValue);

if(sensorValue > threshold) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}

delay(10);
}

I get a message saying 'CapacitiveSensor' does not name a type. I don't understand what this means.

Any ideas?

Please use the code tags it makes it easier to read

#include <CapacitiveSensor.h>
CapacitiveSensor capSensor = CapacitiveSensor(4,2);

int threshold = 1000;
const int ledPin = 12;

void setup () {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}
 
  void loop() {
    long sensorValue = capSensor.capacitiveSensor(30);
    Serial.println(sensorValue);
   
    if(sensorValue > threshold) {
      digitalWrite(ledPin, HIGH);
    }
    else {
      digitalWrite(ledPin, LOW);
    }
   
    delay(10);
  }

Do you have the "CapacitiveSensor" library installed.

I presumed it was pre-installed as there is no reference to installing it in the book.

How do I install it?

You have to download this library, unzip it ( if file is compressed ) and install it : http://arduino.cc/en/Guide/Libraries . Remember to restart Arduino IDE after library is installed.

Thanks guys.

For anyone else struggling with this you can download the folder from here:

http://playground.arduino.cc/Main/CapacitiveSensor?from=Main.CapSense

On a mac you have to unzip the dowloaded zip. Take the folders out of the 'Libraries' folder in the download, and put them into the 'Libraries' folder in Documents/Arduino.

More instructions here: http://arduino.cc/en/Guide/Libraries

but I could only get it to work with the manual installation.