Go Down

Topic: Capacitive sensors as single-pole-multiple-throw (SPnT) switch (Read 1 time) previous topic - next topic


Nov 13, 2013, 06:43 am Last Edit: Nov 13, 2013, 05:15 pm by zilaihong Reason: 1
Hi, I am new to arduino. Please bear with me if some questions are too naive.

What I am thinking about is:
1) Use 4-12 capacitive sensors layed out in a matrix (this sensor http://playground.arduino.cc//Main/CapacitiveSensor?from=Main.CapSense);
2) Each of them would represent a stored number (or an array of number);
3) Arduino would output the stored number of the closest sensor.

Here is an example pic I drew, the red dots are where the fingers are.  Green lines indicate the distances. In this case it would output the stored value of A.

Also if I use an array of number, I would output some of them this way (SPnT switch), and for some of them I would scale each of them with its distance value and sum all the result...


Here is a code I've written, not tested on an arduino yet, can't find it now. This shows how I implement the "switch" and "scaling" features:

Code: [Select]
void loop()  {

  unsigned long currentMillis = millis();
  long sensorlt =  cs_2_4.capacitiveSensor(30);
  long sensorrt =  cs_2_7.capacitiveSensor(30);
  long sensorlb =  cs_2_8.capacitiveSensor(30);
  long sensorrb =  cs_2_12.capacitiveSensor(30);

  // output 1 : control LED blinking speed with "scaling" feature

  lt1 = map(sensorlt, 50, 16000L, 0, lt[1]);
  rt1 = map(sensorrt, 50, 16000L, 0, rt[1]);
  lb1 = map(sensorlb, 50, 16000L, 0, lb[1]);
  rb1 = map(sensorrb, 50, 16000L, 0, rb[1]);
  sum1 = lt1 + rt1 + lb1 + rb1;
  interval1 = map(sum1, 0, 512, 2000, 200);

  if(currentMillis - previousMillis1 > interval1) {
    previousMillis1 = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (output1 == LOW)
      output1 = HIGH;
      output1 = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(GongueGateL, output1);

  // output2 : output the value that's represented by the sensor nearest to flesh.
  sum2 = max (sensorlt, sensorrt);
  sum2 = max (sum2, sensorlb);
  sum2 = max (sum2, sensorrb);

  if(sum2 = sensorlt)
    output2 = lt[2];

  if(sum2 = sensorrt)
    output2 = rt[2];

  if(sum2 = sensorlb)
    output2 = lb[2];

  if(sum2 = sensorrb)
    output2 = rb[2];

  analogWrite(GongueCVL, output2);


Did you have a question? Where is your code? What have you tried?
The art of getting good answers lies in asking good questions.


Did you have a question? Where is your code? What have you tried?

Thanks for reply.
I did a piece of code, just edited the main post.


just edited the main post.

Did you have some purpose in starting this thread? If you're asking for help with a problem, you need to explain what the problem is, and preferably what you've done so far to try to solve it. If you aren't asking for help and just want to show your code off, it would be more appropriate to publish it in the playground.

Go Up