Capacitive touch question

I am building a project that has nothing to do with capacitive touch, but did notice my project responds to it in an undesired way. I’m hoping this simply isn’t going to be a problem, but I’d like to understand what’s happening so I can convince myself that this will not happen when my project is wired into the system it’s monitoring (and no humans are fiddling with the wires), which happens to be my car.

Below is a pretty simple schematic and a pretty simple program. I am currently able reproduce this behavior with this exact hardware and software combination:

#include <SoftwareSerial.h>

void setup() {
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(0, myISR, FALLING);
  Serial.begin(9600);
}

void loop() {
  Serial.println("looping");
  delay(500);
}

void myISR() {
  Serial.println("->isr 0");
  _delay_ms(500);
  Serial.println("->isr 1");
}

When I touch WIRE A to WIRE B (grounding Digital input 2), I get the expected behavior, something to the effect of:

looping
looping
looping
looping
->isr 0
->isr 1
->isr 0
->isr 1
looping
looping

but when I simply hold WIRE B between my fingers, I sometimes get an infinite loop of the ISR firing over and over:

looping
looping
->isr 0
->isr 1
->isr 0
->isr 1
->isr 0
->isr 1
->isr 0
->isr 1
->isr 0
->isr 1
->isr 0
->isr 1
->isr 0
->isr 1

So it seems that input D2 is seeing a falling signal over and over. This seems bad, and seems like I probably need extra components (maybe a capacitor?) to prevent this from happening. I understand a lot of basic components but have never used capacitors.

I actually already have a custom PCB designed, so I’m hoping that I won’t have to worry about this phenomenon when D2 is actually wired to a transistor which is triggered by the starter in my car to connect D2 to ground.

Thanks for any insight!

temp.png

Your body is picking up electrostatic fields from the mains supply and passing it to the input pin, which has a high enough impedance to allow the signal to repeatedly toggle the input state. If you want a demo, touch the input pin of a guitar cord plugged into an amp and hear the ear popping buzz.

If you connect the pin to something low impedance like a sensor output, it can't happen.

aarg: Your body is picking up electrostatic fields from the mains supply

Strictly speaking that's electric fields, as they are not static!

People are often surprized by the voltage you can pick up this way, for instance I'm currently picking up 15Vrms just be being near some mains cables.

Mains cables are almost never screened, here in the UK we have 240Vac on the live wire, 0Vac on neutral and earth (hopefully) - this means on average a mains cable appears to be running at about 80Vac from the perspective of a distant object. Depending on how close you are to cables and how well earthed you are you might be floating at anything from 0V to 80Vac. That's easily enough to fry MOSFETs if you pick them up by the gate pin, note.

Since this is coupling to you through a few pF of capacitance or so, the current available is a few microamps at worst, you'd never feel this.

That 15V I measured above is into the 10M input impedance of a 'scope probe - without that 10M resistor to ground I might be at a considerably higher potential even!

Interesting, thanks to both of y’all. This is obviously why, or one reason why, we want to ground ourselves when we are handling components, soldering, etc. I guess I should invest in one of those wrist ground straps.

What I still don’t get about this whole thing is why in my example above it continuously, or I should say repeatedly, triggers the FALLING interrupt. It seems like it would trigger it once, just like when I connect D2 to GND.

When I modify my code to just print the value of the pin, it’s flipping 1/0 very quickly. No discernible pattern. Anyway, I don’t think this will change my design, I just had to investigate to make sure it’s not going to be a factor.

->loop: 1
->loop: 1
->loop: 1
->isr___: 0
->isr---: 0
->isr___: 1
->isr---: 0
->isr___: 1
->isr---: 1
->isr___: 1
->isr---: 0
->isr___: 1
->isr---: 1
->isr___: 0
->isr---: 0
->isr___: 1
->isr---: 1
->isr___: 0
->isr---: 1
->isr___: 1
->isr---: 1
->isr___: 0
->isr---: 1
->isr___: 1
->isr---: 0
->isr___: 1
->isr---: 1
->isr___: 1
->isr---: 0

jwallis: What I still don't get about this whole thing is why in my example above it continuously, or I should say repeatedly, triggers the FALLING interrupt. It seems like it would trigger it once, just like when I connect D2 to GND.

Because the line voltage alternates 50 or 60 times a second.

Ahhhh, suddenly it's very real. I have never dabbled in AC so I never think in those terms. Thanks-

Seems you do not comprehend what interrupts are for.

Never mind, I won't repeat my standard comment on that unless provoked. :roll_eyes:

Paul__B: Seems you do not comprehend what interrupts are for.

Never mind, I won't repeat my standard comment on that unless provoked. :roll_eyes:

Other than insulting and/or baiting me, I do not find a ton of information in that post...

I'm guessing it was based on the delay I put in my ISR, which was designed and works to filter out false (less than a few hundred ms) signals. Since my application works on the order of tenths of a second and not microseconds, I don't mind the time expense I'm incurring.

So you don't have a problem then.

That's fine. :grinning:

"Works for me..." -Every developer ever

;)