6
\$\begingroup\$

I have a rotating contact (contact breaker of an ICE) that switches between being not connected to anything (floating) and being connected to the case of the ICE. The engine case is connected to ground (same ground as the Arduino). Thus the signal is switching between short times of being on LOW (connected to ground) and mostly being floating. Both of these intervals are much higher than the usual hardware resolution for interrupts on the Arduino - think several microseconds of LOW vs some milliseconds of floating.

Since the "ON" state of the switch connects to ground, I was thinking that I could use the interrupt function of the Arduino to be informed whenever the state changes to LOW, to count how many times the engine rotates. However I have only seen this used in combination with a HIGH signal and not with a floating signal. I was wondering if this would also work and the interrupt would be triggered when the signal switches from floating to LOW.

What are my options to count a signal that switches between floating and the same ground signal as the Arduino?

\$\endgroup\$

2 Answers 2

10
\$\begingroup\$

You can weakly pull the signal high when the switch is not closed using a pull-up resistor. GPIO ports on most micro-controllers have built-in pull-up resistors you can control from software.

\$\endgroup\$
5
  • \$\begingroup\$ I am going to try this tomorrow. setting it to INPUT_PULLUP seems easy enough. I hope the voltage difference between ground and floating is enough to trigger it :) \$\endgroup\$ Jul 15, 2021 at 21:55
  • 3
    \$\begingroup\$ @YanickSalzmann your last sentence from that comment seems like you might still be slightly confused about some of the details. Adding the pull-up resistor (via software or otherwise) causes the input to no longer be floating and any "voltage difference between ground and floating" isn't really meaningful. \$\endgroup\$ Jul 15, 2021 at 22:02
  • 1
    \$\begingroup\$ you are right, I am somewhat confused what a "pull up" resistor is, however this is something I can figure out myself :) \$\endgroup\$ Jul 15, 2021 at 22:12
  • 3
    \$\begingroup\$ @YanickSalzmann Note that sometimes the default pull ups available aren't enough to get the flank steep enough, so you might want to calculate (based on resistor value) or measure (with a scope) the result. \$\endgroup\$
    – Mast
    Jul 16, 2021 at 6:47
  • \$\begingroup\$ @YanickSalzmann A pullup resistor is a resistor between signal and VCC. The SIMPLEST way to do this is to simply put a physical resistor between the Arduino's 5V and signal thus forcing the signal to become 5V when the output floats. This means you are now in a condition to detect switching between 5V and 0V and no longer need to care about 0V and floating \$\endgroup\$
    – slebetman
    Jul 17, 2021 at 4:32
7
\$\begingroup\$

No MCU can directly detect a floating pin, it requires external components, clever software tricks, or at least setting up the GPIO pin properly

That's why you use resistors to pull up the signal so it does not float and can be read as high.

The pull up resistor can be an external physical resistor, or you might also be able to use MCU built in pull ups if they are suitable in your application.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I wouldn't say never... I can think of a few ways you could detect a floating condition with an MCU and an ADC and a circuit with pull ups and pull downs at 2.5V (then switch it to GPIO). Also you can detect a 'non floating' condition \$\endgroup\$
    – Voltage Spike
    Jul 15, 2021 at 22:02

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.