Counting signal switching between floating and LOW in Arduino

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?

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.

• 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 :) Commented Jul 15, 2021 at 21:55
• @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. Commented Jul 15, 2021 at 22:02
• you are right, I am somewhat confused what a "pull up" resistor is, however this is something I can figure out myself :) Commented Jul 15, 2021 at 22:12
• @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.
– Mast
Commented Jul 16, 2021 at 6:47
• @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 Commented Jul 17, 2021 at 4:32

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.

• 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 Commented Jul 15, 2021 at 22:02