Adding more inputs

To add another fabric touch pad, clip another alligator clip to another digital pin. I picked SDA, which is D2 in the Arduino software.
Clip yet another alligator to the non-fabric side of the first resistor. This extends the connection from D9 to the new conductive fabric pad.
Clip SDA (D2)'s other end to the fabric and another big resistor, as shown. Now you can look for a sensor reading from the new addition.
Upload this sketch for changing between two colors with two touch pads:
Download: file
#include <CapacitiveSensor.h>
#include "Adafruit_FloraPixel.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
 * Modified by Becky Stern 2013 to change the color of one RGB Neo Pixel based on touch input
 */


CapacitiveSensor   cs_9_10 = CapacitiveSensor(9,10);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor   cs_9_2 = CapacitiveSensor(9,2);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
//CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
Adafruit_FloraPixel strip = Adafruit_FloraPixel(1);

void setup()                    
{
   cs_9_10.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   Serial.begin(9600);
    strip.begin();
    strip.show();

}

void loop()                    
{
    long start = millis();
    long total1 =  cs_9_10.capacitiveSensor(30);
    long total2 =  cs_9_2.capacitiveSensor(30);
    //long total3 =  cs_4_8.capacitiveSensor(30);

if (total1 > 4000){
  digitalWrite(7, HIGH);
  strip.setPixelColor(0, Color(0,255,0));  
  strip.show();
}
if (total2> 4000){
  strip.setPixelColor(0, Color(255,0,0)); 
  strip.show();
}
  
    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for debug windown spacing

    Serial.print(total1);                  // print sensor output 1
    Serial.print("\t");
    Serial.println(total2);                  // print sensor output 2
    //Serial.print("\t");
    //Serial.println(total3);                // print sensor output 3

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

// Create a 24 bit color value from R,G,B
RGBPixel Color(byte r, byte g, byte b)
{
  RGBPixel p;
  
  p.red = r;
  p.green = g;
  p.blue = b;
  
  return p;
}
This guide was first published on Jan 16, 2013. It was last updated on Jan 16, 2013. This page (Adding more inputs) was last updated on Sep 21, 2019.