Pages: [1]   Go Down
Author Topic: help with capsense  (Read 335 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is probably an easy answer for the seasoned people here.. but i need help.  I am want to use my Leonardo board to sense capacitance.  I am using the capsense library.  I have everything set up correctly and I get capacitance readings that spike when my hand is near or touching the sensor.  Works perfectly.  The part of the code that is killing me is being able to actually make an output pin turn on when the readings pass a set point.  An if statement is not working.  I am stuck

Code:
#include <CapacitiveSensor.h>

CapacitiveSensor   cs_8_4 = CapacitiveSensor(8,4);        // 10M resistor between pins 8 & 4, pin 4 is sensor pin, add a wire and or foil

int led = 13;

void setup()                   
{
  cs_8_4.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example

  pinMode (led, OUTPUT);
 
  Serial.begin(9600);    // initialize serial communications

}

void loop()                   
{
    long start = millis();
    long totalCap =  cs_8_4.capacitiveSensor(30);

    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for debug windown spacing

    Serial.print(totalCap);                  // print sensor output 1
   
    if (totalCap > 500){
      digitalWrite(led, HIGH);
    }
   
    delay(1000);                             // arbitrary delay to limit data to serial port
}

I can watch the output on the monitor jump from around 12 to 1200 as often as i move my hand near it but the output is not responding.  I am using pin 13.. the led pin.. just as an example right now to see if i can turn that pin on.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 614
Posts: 49385
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    if (totalCap > 500){
      digitalWrite(led, HIGH);
    }
Add a print statement in the block. If the print happens but the LED does not come one, you have a problem with the LED.

Once it turns on, though, there is nothing to turn it off until you reset the Arduino. Is that really what you want?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    if (totalCap > 500){
      digitalWrite(led, HIGH);
    }
Add a print statement in the block. If the print happens but the LED does not come one, you have a problem with the LED.

Once it turns on, though, there is nothing to turn it off until you reset the Arduino. Is that really what you want?

Good point... i do not... the output pin is going to control a tiny mechanically held contact.  Basically when the sensors goes over five hundred it should send a 5v pulse to latch the contact.. and the next time the sensor goes over 500 the output pin sends another 5v pulse to unlatch the contact.

Thanks for the code bit too!!!
Logged

Pages: [1]   Go Up
Jump to: