First lesson...
OK, before we dive too deeply into this, a reading assignment:
This is the Arduino writeup on the Capacitive Touch library we'll be using. Before you start programming, you'll need to download and add this to your IDE (the Arduino programming environment - runs on Mac, Linux, and Windows) and include it, as well as the servo library (which is included with the IDE)
https://playground.arduino.cc/Main/CapacitiveSensor/
Don't let it scare you.... it's a pretty detailed discussion of it, but what we're going to do is pretty simple and straightforward. (He says optimistically...)
Now, I'm going to load this in and play with it over the next couple of days, and I'd suggest you might want to as well if you have an Arduino handy.
This is the code for the demo of Capacitive Touch from the web site linked 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
CapacitiveSensor cs_4_5 = CapacitiveSensor(4,5); // 10 megohm resistor between pins 4 & 6, pin 6 is sensor pin, add wire, foil
CapacitiveSensor cs_4_8 = CapacitiveSensor(4,8); // 10 megohm resistor between pins 4 & 8, pin 8 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);
long total2 = cs_4_5.capacitiveSensor(30);
long total3 = cs_4_8.capacitiveSensor(30);
Serial.print(millis() - start); // check on performance in milliseconds
Serial.print("\t"); // tab character for debug window spacing
Serial.print(total1); // print sensor output 1
Serial.print("\t");
Serial.print(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
}
=======================================
... and that's all there is to it. In fact, if we cut out all the comments it's even less intimidating. Here's the same sketch, without comments:
========================================
#include < CapacitiveSensor.h>
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2);
CapacitiveSensor cs_4_5 = CapacitiveSensor(4,5);
CapacitiveSensor cs_4_8 = CapacitiveSensor(4,8);
void setup()
{
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);
Serial.begin(9600);
}
void loop()
{
long start = millis();
long total1 = cs_4_2.capacitiveSensor(30);
long total2 = cs_4_5.capacitiveSensor(30);
long total3 = cs_4_8.capacitiveSensor(30);
Serial.print(millis() - start);
Serial.print("\t");
Serial.print(total1);
Serial.print("\t");
Serial.print(total2);
Serial.print("\t");
Serial.println(total3);
delay(10);
}
=========================================
Not much to it, is there?
OK.... Now I'm going to build this little thing, program my Arduino Uno with this sketch, and play with it. I've already got several pennies soldered to single wires for test purposes, and I'm probably going to play with a little bit of aluminum foil, too.
I'm also going to experiment with resistor values. In general, the higher the resistor value, the more sensitive the sensor is. My goal is to mount the sensors in a picture frame, and have them read through the glass. I don't want them reading proximity, because I'm hoping to use a small 4 x 6 or 5 x 7 picture frame as the touch panel. This means my fingers will be fairly close to sensors I don't want to trip, and therefore need the sensor to have a very limited range.... so I'll be starting with a 10 MOhm and probably working down from there until I find the value that triggers at no more than a few millimeters from the sensor.
Other things I'll be trying (after adding the servos into the mix) is seeing if I can put two sensors on one input.... which would let me run duplicate panels on each side of the module.
Oh, by the way, in case it wasn't clear above... I'm controlling 5 sensors (one pin each, plus one (i hope) common pin)), and 5 servos (One data pin each, ) which comes to 11 pins, not counting the +5v and Ground.... this should... I think... all run off a single Arduino. You don't need 1 per turnout. It would still be a bargain even at that, but I'm hoping to do MUCH better.