I am currently working on a project with an arduino yun and some sensors.
I decided not long ago to handle the case where a sensor was unplugged.
So I have 3 sensors, respectively on A0, A1 and A2, i read the value with analogRead and the corresponding slot ( analogRead(A0) for example).
Until now, everything's ok.
Then, I decide to unplug a sensor and see the value it sends me, to handle the case...
Aaaaand, surprise !
I get the exact same range of values, on every analog slot.
I tried to link an analog slot to 5V, i do have the 1083 result, and to the ground, the 0.
So... i'm kinda lost right know, i have no idea why this is happening.
Does someone have had a similar problem ?
If you try to read an analog input, and there is nothing connected to that on, you will get unpredictable results. What you read will depend on whatever charge is on that floating pin, and that charge might vary depending on the voltages on adjacent pins. But whatever value you get, it will always be in the same 0 to 1023 range as a valid reading. The analog converter has no idea whether something is actually connected or not, and it can't return any values outside of the range of 0 to 1023.
I'm not sure what you were expecting to see, but your observations seem like what would be expected.
If you want to be able to detect a disconnected input, you will need to add some sort of pull-up or pull-down resistor to bring a floating input to a known state. And hopefully that state doesn't correspond to a bald reading. You have to be careful, however, to take that added resistance into account as it will affect your readings when the sensor is connected.