1

I'm trying to figure out how the Arduino Capacitive Sensing Library https://playground.arduino.cc/Main/CapacitiveSensor/ works. It says:

When the send pin changes state, it will eventually change the state of the receive pin.

However, when I look at the following schematic, I don't understand why this is the case. It seems like the send pin is set to OUTPUT and HIGH and the receive pin to INPUT with deactivated pull-up. I think it's okay to ignore the capacitance at first, yes? Doesn't all the voltage drop over the resistor R and the receive pin will just be floating and showing LOW or HIGH randomly?

schematic

Source: https://playground.arduino.cc/Main/CapacitiveSensor/

1 Answer 1

2

If we ignore the capacitance of the input pin, then it would instantly follow the voltage of the send pin. A voltage drop over the resistor only happens if a current is flowing though it, which cannot happen without any capacitance the receive side. Without current a resistor is just a wire.

A floating pin doesn't directly have its state randomly changes between LOW and HIGH. That can only be the result as the voltage on that pin is changes by the noise. We need the noise to not be directly in the logic voltage range, so that the state of the digital input pin is not totally dictated by noise. That often the case. Also the additional capacitance added by the sensing foil helps with filtering the noise.

The actual measurement works as follows: We set the send pin to a known state and wait a bit (to fully load or unload the capacitance on the pin). Then we change the send pin to the other state and count the time until we see that change on the receive pin. That is when the capacitance of the pin is loaded. Then we are doing that procedure many times, averaging the measured time. What the receive pin does outside of the measurements is not important. During the meausrement its state is mainly dictated by us setting the send pin. Though the library might use some optimization to get a better reading. You could read the libraries code to learn more about that.

8
  • Huh okay. Thank you for the answer! I think I'm learning a lot new stuff here. So you're saying when I simply connect two GPIO pins with a resistor, one is set to output, one is set to input - then no current is flowing at all and therefore the resistor is like a wire? If no current is flowing, how does the input pin "know" the output pin's state? Oct 9, 2021 at 13:44
  • I wanted to say, that there actually is a bit of current flowing, because you simply cannot leave out the capacitance of the pin in this case. Also the digital input pin is basically a Schmitt trigger, which only has very very low input current. And why shouldn't the input pin "know" the state? It senses voltage, not current. I'm not sure, where the confusion is here.
    – chrisl
    Oct 9, 2021 at 14:47
  • I'm sorry for the confusion. Yes, it measures voltage. So I thought all the voltage has already dropped over the resistor, so nothing is left to measure at the input pin. But that's the point, right? There is current flowing as long as the "capacitor" (sensor plate + human) isn't charged, so the voltage drops over the resistor. The input pin is low. When it's charged, no more current flows and the resistor becomes a wire, the input pin is now high. Is that correct? Oct 9, 2021 at 15:28
  • Yes, thats correct
    – chrisl
    Oct 9, 2021 at 16:48
  • Ahh, thank you. I think I'm beginning to get a grip on it. Sorry, another follow-up question: so the "capacitor" gets fully charged/discharged for every measuring cycle? (I would have thought that's quite a lot of electric charge?) Oct 9, 2021 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.