Can Digital Input differentiate between +5, Gnd, & Open?

I'm working on a project that would require my board to read whether an input has continuity with ground, is at +5 V, or is open.

Is this possible with a digital input, or would I have to somehow split it to two different inputs or use analog?

Thanks,
Jesse

A digital input will pull up or down, only 2 states, and open would float either or... If you use an analog pin, and pull up to 2.5 volts, you can detect if ground is connected, which will pull down, or +5 is connected, which will pull up to +5, and an open would read 2.5 volts.

Read the pin. If it reads HIGH set it OUTPUT LOW briefly, set it INPUT, wait a moment and read again. If it is still HIGH it is connected to 5V, otherwise it is unconnected. You need probably add a cap and a resistor to make it more reliable.

In my mind I am thinking you might be able to use a voltage divider circuit that takes constant 5volt and drops it’s down to say 2-3 volts into a analog pin for ADC reading.
The “ground leg” of the divider circuit would be your actual connection to what your testing.

If it’s its grounded pin voltage will be where it’s supposed to be.
ADC value would be lowest.

If it’s open, the pin voltage will rise.
ADC will increment to whatever is left over of the voltage drop of the one active resistor.

If it’s +5 volts the voltage will rise higher than open voltage.
ADC will be receive 5volts minus whatever R1+R2/4 voltage drop.

Never tried that in a circuit but should be pretty easy to test.

Some Arduinos, like esp8266 have pins with pull down resistors. If you use one of those, you could use a pin with a pull up and a pin with a pulldown to sense the state.
If when the input_pullup is enabled and the other pin is input, if input is LOW then it is being driven low.
If when the input_pulldown is enabled and the other pin is input, if input is HIGH then it is being driven high.
If neither of those is true, the pin is floating.

--- bill

Why do you want to determine that? Perhaps there is an easier way to do what you actually want.

Connect a high value (>= 1Megohm) resistor between pin and ground.

The pin set to INPUT will return a LOW.
The pin set to INPUT_PULLUP will return a HIGH.

Unless something is connected.
In that case both states will return the same value.
Leo..

Wow, thanks for all the replies. A lot of great ideas in here. I'm just going to have to try to test some of these options and see what works best for my application. I'm basically trying to get three different states out of a simple switch connected using only two wires.

I'm basically trying to get three different states out of a simple switch connected using only two wires.

You should have said that first.
It sounds a totally different task than:-

I'm working on a project that would require my board to read whether an input has continuity with ground, is at +5 V, or is open.