Hello. I have a sensor connected to an Arduino Pro Mini trough a cable. It gives a voltage between 0V and 4,5V wich I read with an analog input.
My problem is that when the cable is disconnected, the analog pin reads random voltage and I can't be sure wether it is a real read or a false read because the cable disconnected.
So, at the moment I'm thinking how to be sure that the read is the sensor and not the a false read.
At the moment I'm considering
-
Adding to the cable two extra pins interconnected, so I can read if both pins are connected. The problem here it is that the sensor includes the cable and it is not easy to change it so I want to consider other options.
-
Using a MOSFET to power on/off the sensor and compare the results, if they are different, the cable is connected otherwise it is not.
-
Using the pull-up resistor of the arduino analog input pin so I can check different voltages. I read the sensor without the pull up resistor and from time to time I enable the pull up resistor to check the cable. If I get a 5V I asume the cable is not connected and otherwise it is. I didn't test this yet and actually I do not know the behaviour when the sensor is connected and if it is connected, if it could be damaged.
-
When the cable is not connected values readed have more variance. Calculating the variance could be an accurate way for determining if the cable is connected?
Do you think there may be another solution? Wich one do you think it is the best approach?
Thanks in advance