Hello guys,
I have problem related with CapacitiveSensor library and Arduino's ground. I am new to electronics so please forgive me if I miss something.
I made little PCB which photo I attach to this post. Explanation: obviously circle in the middle is supposed to be my cap sensor where everything outside it is supposed to be grounded. In the middle I have few unconnected pins for some led. Capacitive sensor works pretty well if it is connected to the board exclusively (if we don't mind for huge noise in the signal caused probably by many sources...). I monitor it's values on Arduino's serial monitor. Problem starts when I try to plug ground for the grounded parts of the sensor - just then I get -2 value on serial monitor and it is appearing every few seconds (like maybe 5 seconds). When I disconnect ground it starts working again.
I checked all the pins and nothing seems to short there (check it with multimeter).
My pin setup is:
PIN 4 - Cap Sensor OUT (with 1M ohm resistor)
PIN 8 - Cap Sensor IN
GND - pretty obvious
I should mention that connecting single led between +5 and GND doesn't give this Arduino's "stuck" effect.
I tried also to unmount the PCB from the wall mount as PCB and the mount are "connected". It does NOT change a thing.
My code is:
CapacitiveSensor capSensor = CapacitiveSensor(4, 8);
bool isOn = false;
const int ledPin = 9;
int current = 0;
int threshold = 20;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
// store the value reported by the sensor in a variable
long sensorValue = capSensor.capacitiveSensor(30);
Serial.println(sensorValue);
if (sensorValue > threshold) {
val++;
if (current == 0){
if(val > errorTh){
if(!isOn) {isOn = true; current = 1; } else { isOn = false; current = 1; }
}
}
} else { val = 0; current = 0; }
if(isOn){
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
delay(10);
}
In code I used led to check if it reacts correctly if I switch off serial output - and in fact it does not make any difference.
Please help - I'm banging my head against the wall here.
Thanks in advance!
Best regards,
Tom
