Check if pin is floating/disconnected/high-z?

So, I have an Arduino mega in an inaccessible location, wired into a series of external components (Radios, Gyros, GPS, Servos etc...) via connectors.

Now, I want to program the Arduino so that the system can give me a Boolean value as to whether each pin is connected to anything (+ Voltage or Ground), or whether it is disconnected (i.e. Floating, or as some people call it, high-z). Of course, I could poll each pin to see if it was fluctuating, but this wouldn't work for devices like the Gyro because one of the pins changes between HIGH or LOW depending on whether the gforce is above or below a certain amount.

I'm doing this so that the system can tell the difference between the gyro/servos coming loose from their connectors, or just operating normally.

So, is there a way of telling if a pin is connected or if it just left floating? Or is it not that simple?

Thanks for your help!

Some pins are inputs, some pins are outputs?
Are you able to commit a 2nd IO pin for each connectorized pin?

You could connect all of the input pins to a common rail with a 100K resistor each. If the pin follows the rail as you toggle the rail HIGH and LOW then the input pin is likely not connected to anything else. The resistors should be weak enough that they don't interfere with any actual inputs.

CrossRoads:
Some pins are inputs, some pins are outputs?
Are you able to commit a 2nd IO pin for each connectorized pin?

Some are inputs, some are outputs, yes. Unfortunately I'm utilizing all but 4 pins, so I don't have another spare.

johnwasser:
You could connect all of the input pins to a common rail with a 100K resistor each. If the pin follows the rail as you toggle the rail HIGH and LOW then the input pin is likely not connected to anything else. The resistors should be weak enough that they don't interfere with any actual inputs.

I thought of doing that too, but a few of the pins are outputs to devices (including an array of rocket engine igniters, don't ask lol) which would trigger if I toggled them high.

Right now my only solution I have is to monitor the pin and see how many times it changes over a 50ms period, and if it is over 20 then it is assumed floating. This isn't ideal as it's also going to be piloting a quadrucopter which for balancing reasons can't afford to suddenly be held waiting for 50 milliseconds, so if there are any other suggestions I'd still appreciate them, thanks!

For detecting unconnected input pins, do as johnwasser suggests. You can use an even higher value resistor e.g. 1M if you take the right precautions when reading the pin.

For detecting unconnected output pins, you could do the same if you build pulldown resistors (e.g. 1K) into your rocket igniters, or use some other mechanism so ensure that it takes more than a few uA to trigger them.

RjSowden:
a few of the pins are outputs to devices (including an array of rocket engine igniters, don't ask lol) which would trigger if I toggled them high.

You don't toggle the pin HIGH. You set the pin to INPUT and toggle the pull-rail HIGH and LOW. The rail can only source/sink 50 microamps (0.05 mA) because of the resistors. Do any of the outputs connect to high impedance inputs? That might cause a problem if the input doesn't have a pull-down or pull-up. For example if you are driving a Darlington transistor pair to switch current to a motor, relay, or ignitor the 50 microamps might be enough to cause significant current flow.

If the pin reads as HIGH when you set the pull-rail to HIGH and LOW when you set the pull-rail to LOW then it not connected to anything with an impedance lower than about 100K.

Quadcopter and rocket engines...

If there isn't a YouTube video of this, I'm going to be sorely disappointed.

Much the same sentiment as above - if you have rocket igniters connected to pins on the micro, you really need pull-downs - of about 1K - on them anyway.

Arguably, you should have each of them passing through a NOR gate, the second input of which is (in common) driven by a separate output pin through an inverter, requiring both a high and low output from the micro simultaneously to actuate the igniters.

dc42:
For detecting unconnected output pins, you could ... build pulldown resistors (e.g. 1K) into your rocket igniters, or use some other mechanism so ensure that it takes more than a few µA to trigger them.

Capacitive Sensing of Floating Node
Connect a capacitor to the gyro pin on Arduino. The other plate of the capacitor is from a resistor from a digital output (DO) to the gyro pin. Connect the node between the capacitor and resistor (RC) to a digital input (DI). If the gyro pin is floating, the capacitor will behave differently than if the gyro pin is driven by the gyro output. Toggle the DO to start a test. The DO will drive the resistor which drives the RC node where the DI and capacitor are connected. If the gyro pin is floating, a digitalRead(DI) will detect fast switching of the RC node. If the gyro pin is driven by the gyro, the digital input DI will detect slow switching of the RC node.

SirNickity:
Quadcopter and rocket engines...

If there isn't a YouTube video of this, I'm going to be sorely disappointed.

Don't worry. If there isn't now, there will be when I'm done.

johnwasser:

RjSowden:
a few of the pins are outputs to devices (including an array of rocket engine igniters, don't ask lol) which would trigger if I toggled them high.

You don't toggle the pin HIGH. You set the pin to INPUT and toggle the pull-rail HIGH and LOW. The rail can only source/sink 50 microamps (0.05 mA) because of the resistors. Do any of the outputs connect to high impedance inputs? That might cause a problem if the input doesn't have a pull-down or pull-up. For example if you are driving a Darlington transistor pair to switch current to a motor, relay, or ignitor the 50 microamps might be enough to cause significant current flow.

If the pin reads as HIGH when you set the pull-rail to HIGH and LOW when you set the pull-rail to LOW then it not connected to anything with an impedance lower than about 100K.

Ahh right, I get you now! Sorry, I was a little slow on the uptake. All the stuff which is high impendence stuff is controlled via relay, so it's fine on that front.

Paul__B:
Much the same sentiment as above - if you have rocket igniters connected to pins on the micro, you really need pull-downs - of about 1K - on them anyway.

Arguably, you should have each of them passing through a NOR gate, the second input of which is (in common) driven by a separate output pin through an inverter, requiring both a high and low output from the micro simultaneously to actuate the igniters.

Noted, and I'm adding that in now anyway as it's a sensible safety precaution, on top of all the mechanical interlocks :slight_smile:

Thanks all of you for helping! I'm going with what johnwasser recommended though, simple and effective!

johnwasser:
You could connect all of the input pins to a common rail with a 100K resistor each. If the pin follows the rail as you toggle the rail HIGH and LOW then the input pin is likely not connected to anything else. The resistors should be weak enough that they don't interfere with any actual inputs.

Hi John, it would be great if you can post schematic of how to achieve this? Apparently, i've been searching a solution for a long time and many sites/pages all refer to this response of yours. However, for new learners of electronics, your technical explanation is difficult to understand. So you if you can post a schematic with an example for 2 pins, that would help many of them who are seeking answers including myself. Thanks a lot.