CapSense giving unpredictable readings

Hello,

I have arduino pins 4 and 8 connected with a 1M resistor and a wire coming from 4, hooked up to a plant. At standby, I usually get readings somewhere in the 20s, when I touch the plant, depending on how far from the lead hook up, I get readings from 50-300.

Usually this works perfectly.

After minutes or hours, I get readings that are in the 400s at standby and 1000 when touched...or 200 at standby and 800 when touched etc. If i hit the reset pin on the arduino, everything starts back and I get between 20-300 again.

I set up some code to automatically reset the arduino every 10 seconds but this didn't solve the problem. I was still getting the number spike. Only a hard long push of the reset button seems to reset the read back.

So my questions are...
is there any components I could wire up to make this not happen? A diode? A capacitor?
Is there anything I could put in the code to keep my reading steady?

Here is what I have so far:

#include <CapacitiveSensor.h>

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


const int numReadings = 10;
//smoothing stuff
long readings[numReadings];      // the readings from the sensor
long index = 0;                  // the index of the current reading
long total = 0;                  // the running total
long average = 0;                // the average

//int inputPin = A0;

int resetTime;

void setup()                    
{
  digitalWrite(resetPin, HIGH);
  Serial.begin(9600);
  //smoothing stuff
 for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;            
   
}

void loop()                    
{ 
 
  int CurrentTime = millis();
  
  /*if (CurrentTime >= resetTime+10000){
    digitalWrite(resetPin, LOW);
    delay(1000);
    digitalWrite(resetPin, HIGH);
    resetTime=millis();
    Serial.println("RESET!");
  }
  
  resetTime++;*/
  
  // subtract the last reading:
  total= total - readings[index];         
  // read from the sensor:  
  readings[index] = cs_4_8.capacitiveSensor(10); //resolution set to 10
  // add the reading to the total:
  total= total + readings[index];       
  // advance to the next position in the array:  
  index = index + 1;                    

  // if we're at the end of the array...
  if (index >= numReadings)              
    // ...wrap around to the beginning: 
    index = 0;                           

  // calculate the average:
  average = total / numReadings;         
  // send it to the computer as ASCII digits
  Serial.println(average);   
  delay(10);        // delay in between reads for stability            
 
}

How is the Arduino powered? Batteries, via USB in a computer, if it is a laptop is it plugged in, etc.

Is the ground of the Arduino grounded, or at least connected to something large?

CapSense is measuring an increase in capacitance through you. But part of the equation is -your- capacitance to the circuit ground. If it is grounded, then to everything conductive nearby that is grounded. If not grounded, then it will be very important exactly where you stand in relation to the plant and the Arduino.

thanks for the help. the arduino is plugged into a desktop computer via usb so it is grounded through that. is there any additional way i should be grounding it you think?

the weird thing is, though, is that i get different readings on resetting the arduino even though i'm still sitting where i'm sitting and touching the plant exactly where i was before....is this a ground issue?

How are you connecting to the plant? Is the plant in a pot? Is it sitting on a concrete floor?

Perhaps the conductivity of the plant is changing. This method of capacitance measurement is putting a pulsing DC current/voltage on the plant. Perhaps try a 0.01uF capacitor between the Arduino pin and the plant.

Cool thank you. I'm trying to 103 cap right now. Seems to be running smooth so far but I need to test for a few hours.

The plant is in soil, in a ceramic pot, on a wooden table.

Any other foreseeable problems besides grounding? Or is grounding 99% of the time the issue with stuff like cap sensing?

thanks so much again for the help

Per datasheet, resetting the board by doing things to the reset pin from within code running on the chip will not fully reset the chip. The correct way to generate a reset from software is a watchdog reset.

Even AC current may have an effect on the plant, but it should be better than DC pulses.

Although... since the plant isn't grounded, I suppose it was floating at AC anyway. Hm.

How are you connecting to this? Probe in the soil? Pin in the plant?

CapSense giving unpredictable readings

Hold the front page, no one has ever reported this before.

Sorry but they have, the whole cap sense technique as used in this example is not stable. You will know that if you would have done a search of this forum. A lot is to do with the stability of your circuit, you can't just lash something up on solder-less bread board and expect it to be rock stable.

He's right. In fact, what you really should do with CapSense is not look for an absolute reading, instead look for relatively quick changes in the reading. So it drifts slowly over time, if it still changes when you touch it or get close, you are In Like Flint.