Author Topic: Capacitive Touch Sensors  (Read 3291 times)

acotph

  • Newbie
  • *
  • Posts: 1
Capacitive Touch Sensors
« on: September 15, 2015, 06:54:35 pm »
Hi,

I'm very new to arduino and digispark, and am working on a simple lamp project using an LED strip and a digispark.  I have the prototype working with my arduino UNO, but am having difficulty transferring it over to the digispark.  I think the problem is coming down to the types of pins I'm using on the digispark, which is all a bit out of my depth.  I've downloaded the chip schematics for both in an attempt to compare and properly transfer over my wiring, but I have no idea what I'm looking at.  Also, debugging with the digispark is difficult since I can't use the serial monitor.

I have two capacitive rods and an LED strip, and I'm trying to adjust the brightness of the LED strip using the rods as buttons for increasing and decreasing the brightness.

It looks like one other user has had the same issues, but resolved them here: http://digistump.com/board/index.php/topic,1403.msg6441.html#msg6441

I've tried the pins gogol suggested but still have no luck.  My digispark is acting very strange, ie. detecting the capacitance change every second, instead of continuously.  Basically I'm lost.

I'm using the CapacitiveSensor library (http://playground.arduino.cc/Main/CapacitiveSensor), and have wired the sensors like this (only 2 sensors total):



and finally, here is my code:

Code: [Select]
#include <CapacitiveSensor.h>
#include <Adafruit_NeoPixel.h>

  const int numSensors = 2;
  const int inputPins[] = {4, 1};
  int leftRod = 0;
  int rightRod = 0;
  int brightness = 10;
  int PIN = 3;


CapacitiveSensor *sensors[2];
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

    for (int i = 0; i < numSensors; ++i) {
    sensors[i] = new CapacitiveSensor(2, inputPins[i]);
  }

  strip.setBrightness(255);
  pinMode(PIN, OUTPUT);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  brightness = loadTimings();
  lampColor(brightness);
}

float loadTimings() {
  leftRod = sensors[0]->capacitiveSensor(3);
  rightRod = sensors[1]->capacitiveSensor(3);
 

  if (leftRod>20){
    brightness+=5;
  }

    if (rightRod>20){
    brightness-=5;
  }

  if (brightness<10) brightness=10;
  if (brightness>255) brightness=255;
  return brightness;
}


int lampColor(float brightness){

  float ratio=brightness/255;
  float red = ratio*255;
  float green = ratio*100;
  float blue = ratio*60;
 
    for (int i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, red, green, blue);       
      }
      strip.show();
   

}

I apologize for the huge amount of information, I'm trying to provide every detail I can.  I'm so close to finishing my first project but have hit this wall and appreciate any help :)

Thanks!
Alex

defragster

  • Sr. Member
  • ****
  • Posts: 467
Re: Capacitive Touch Sensors
« Reply #1 on: September 15, 2015, 10:54:35 pm »
I have not tried this on any device yet.  I clicked the Arduino link - it notes adding a cap can help - depending on the size of your touch pieces, the digispark may not work on the same levels to maintain the charge.  Also in the reading I did before, the chosen resistor is a factor in the sensitivity.  These two things may in conjunction with the electrical properties of the digispark may be a factor - and the load you are driving with the LED's - try it with minimal load perhaps - enough to see it work, a single dim LED - or just use the strip off and on the dimmest level on a single color.

That and double check against what worked for Gogol in the linked thread.  And it seemed there was a ref to another library that may function better on the digispark.

If you get it working please update - and if you had a pic showing your wiring and the touch metal used it might help.