Sensor connected detection

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

I think I would try the pull-up resistor. But I would also try external pull-up resistors.

If you choose a high value, it should not affect the reading too much and should not damage the sensor. Try different values like 100K, 470K, 1M to see what effects these have and what readings you get when the sensor is connected and not connected.

1 Like

In my case I have a water level detector that is 15 meters away and I use a sensor that generates a voltage between 0.5 and 4.5 Volts, which is connected to A0 of an Arduino Nano. In order to detect faults in the wiring, it was enough to place a 47Kohm resistor between pin A0 and digital pin D3. In measurement mode I set pin D3 as INPUT (pinMode(D3, INPUT)) and measure A0 with analogRead(A0). To detect faults, I change D3 as OUTPUT and assign it Low level and measure A0, then I change D3 to High level and measure A0. If A0 is High with D3 high and A0 is Low with D3 low the cable is cut. The sensor is not damaged because the load impedance is very high 47Kohms. In my case the measurement was not altered because D3 is as INPUT.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.