Tuesday, October 1, 2013

About CapacitiveSensor in Ardunio --Wanfang

CapacitiveSensor is a library in Ardunio,




Capacitive sensing may be used in any place where low to no force human touch sensing is desirable. An Arduino and the library may be used to sense human touch through more than a quarter of an inch of plastic, wood, ceramic or other insulating material (not any kind of metal though), enabling the sensor to be completely visually concealed.

Step 1:
If you cannot find a example file in your ardunio, you may need to download a library here:
http://playground.arduino.cc//Main/CapacitiveSensor?from=Main.CapSense

Step 2:
What you need in hardware part is a large resistor like 10MΩ and foil with a long wire or just a wire.
Put the large resistor between port 2 and port 4.
Put wire's one end on port 4;

Step 3:

Use the example file if you cannot find it in your File->Examples->CapacitiveSensors, you can just copy the code below:(Make sure that you have CapacitiveSensor.h from the link above)

#include <CapacitiveSensor.h>

/*
 * CapitiveSense Library Demo Sketch
 * Paul Badger 2008
 * Uses a high value resistor e.g. 10 megohm between send pin and receive pin
 * Resistor effects sensitivity, experiment with values, 50 kilohm - 50 megohm. Larger resistor values yield larger sensor values.
 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
 * Best results are obtained if sensor foil and wire is covered with an insulator such as paper or plastic sheet
 */


CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        // 10 megohm resistor 
//between pins 4 & 2, pin 2 is sensor pin, add wire, foil


void setup()                    
{

   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);// turn off autocalibrate on channel //1 - just as an example
   Serial.begin(9600);

}

void loop()                    
{
    long start = millis();
    long total1 =  cs_4_2.capacitiveSensor(30);

    Serial.print(total1);                  // print sensor output 1
    Serial.print("\n");
    

    delay(10);                  // arbitrary delay to limit data to serial port 
}

Touch the other end of your wire and check the number in your serial monitor, your output is there.

You can learn more at this link : http://playground.arduino.cc//Main/CapacitiveSensor?from=Main.CapSense

No comments:

Post a Comment