I want to use the Arduino to detect the state of a signal. The signal, however, can be one of three states. Sometimes it will be at ground; sometimes is will be at 5 volts; and sometimes it will be completely disconnected from anything. I'm trying to think of an effective way of determining the state of the signal. I figure all inputs need a pull-up or pull-down resistor. If I use a pull-up resistor, for example, I can't think how to figure out if the signal is actually at 5 volts, or if the signal is floating disconnected and the Arduino is just seeing 5 volts from the pull-up. One thought was to pull it up to 3 volts or something, then do analog reads to see if it's grounded, 3 volts (suggesting the signal is floating), or 5 volts. Anyone have a better idea?
Sure, use two weak (like 100K) resistors between 5V and Gnd, and an analog input at the juncture.
Nothing connected, will analogRead () will return ~ 512 = 2.5V.
5V connected, will read around 1023/5V.
0V connected, will read around 0/0V.