Capacitive touch - No additional components
 Show and Tell (Share your projects here)   Started by Daniel Alich   2018-10-31 12:10:19 -04:00   Comments: 2    Viewed: 37

  1. Daniel Alich
    Daniel Alich Member Staff Member
    Found this little libary that will allow for Capacitive touch on the Analog pins with no additional wires.

    Install the.zip libary.  Look under examples for ACD touch -> Buttons

    https://github.com/martin2250/ADCTouch




    #include <ADCTouch.h>

    int ref0, ref1; //reference values to remove offset

    void setup()
    {
    // No pins to setup, pins can still be used regularly, although it will affect readings

    Serial.begin(9600);

    ref0 = ADCTouch.read(A0, 500); //create reference values to
    ref1 = ADCTouch.read(A1, 500); //account for the capacitance of the pad
    }

    void loop()
    {
    int value0 = ADCTouch.read(A0); //no second parameter
    int value1 = ADCTouch.read(A1); // --> 100 samples

    value0 -= ref0; //remove offset
    value1 -= ref1;

    Serial.print(value0 > 40); //send (boolean) pressed or not pressed
    Serial.print("t"); //use if(value > threshold) to get the state of a button

    Serial.print(value1 > 40);
    Serial.print("tt");

    Serial.print(value0); //send actual reading
    Serial.print("t");

    Serial.println(value1);
    delay(100);
    }
    Daniel Alich, 2018-10-31 12:10:19 -04:00
  2. Daniel Alich
    Daniel Alich Member Staff Member
    This code example will utilive 4 capacitive inputs on A0 - A3.  

    Results for amalog values will be displayed int he serial monitor.

    #include <ADCTouch.h>

    int ref0, ref1, ref2, ref3; //reference values to remove offset

    void setup()
    {
    // No pins to setup, pins can still be used regularly, although it will affect readings

    Serial.begin(9600);

    ref0 = ADCTouch.read(A0, 500); //create reference values to
    ref1 = ADCTouch.read(A1, 500); //account for the capacitance of the pad
    ref2 = ADCTouch.read(A2, 500); //create reference values to
    ref3 = ADCTouch.read(A3, 500); //account for the capacitance of the pad
    }

    void loop()
    {
    int value0 = ADCTouch.read(A0); //no second parameter
    int value1 = ADCTouch.read(A1); // --> 100 samples
    int value2 = ADCTouch.read(A2); //no second parameter
    int value3 = ADCTouch.read(A3); // --> 100 samples

    value0 -= ref0; //remove offset
    value1 -= ref1;
    value2 -= ref2; //remove offset
    value3 -= ref3;

    Serial.print(value0 > 40); //send (boolean) pressed or not pressed
    Serial.print("t"); //use if(value > threshold) to get the state of a button

    Serial.print(value1 > 40);
    Serial.print("tt");

    Serial.print(value2 > 40); //send (boolean) pressed or not pressed
    Serial.print("t"); //use if(value > threshold) to get the state of a button

    Serial.print(value3 > 40);
    Serial.print("tt");

    Serial.print(value0); //send actual reading
    Serial.print("t");

    Serial.print(value1); //send actual reading
    Serial.print("t");
    Serial.print(value2); //send actual reading
    Serial.print("t");

    Serial.println(value3);
    delay(100);
    }
    Daniel Alich, 2018-10-31 12:21:58 -04:00
  3. (You must log in or sign up to post here)

Report Post

Write your reason

Log in | Sign up
Terms & Conditions!
Help!