Avoid floating input

Hello.

I'm trying to detect when a device connected in analog input is working wrong or is disconnected, the problem is that when the device (for example a soil moisture sensor) is working fine I have similar values than when is damaged, so I cant detect the problem.

Is there a way to avoid this problem?

Thanks

I'm trying to detect when a device connected in analog input is working wrong or is disconnected, the problem is that when the device (for example a soil moisture sensor) is working fine I have similar values than when is damaged, so I cant detect the problem.

Is there a way to avoid this problem?

You need to be more specific. Post your data.

Also what devices?

Is there a way to avoid this problem?

A high impedance pull up resistor will solve it.
Make it 10 times the value of the impedance of your sensor.

If the sensor impedance is low enough, you could use the internal pullup resistor.
pinMode(A0, INPUT_PULLUP);
Leo..

Doesn’t anyone have a problem with the OP’s claim that the read value is the same whether the sensor is good or damaged ?

Moisture sensors are generally simple. It reads the resistance relative to moisture content. If it was damaged it could read anything. If you want to verify it is not damaged you can use an analog switch to switch a known calibration resistor across it. If is not damaged it will return the correct value.

Doesn't anyone have a problem with the OP's claim that the read value is the same whether the sensor is good or damaged ?

I think having some redundancy and comparing readings is in order.

.

I think having some redundancy and comparing readings is in order.

Great idea. Order a dozen sensors . What's the chance all of them will be bad ?

raschemmel:
Great idea. Order a dozen sensors . What's the chance all of them will be bad ?

The probability of one being bad multiplied together twelve times.

Wawa:
If the sensor impedance is low enough, you could use the internal pullup resistor.
pinMode(A0, INPUT_PULLUP);
Leo..

Its a Soil Moisture Sensor YL-69 (https://www.amazon.es/MW-Hygrometer-Detection-Moisture-Compatible/dp/B00D8QAWEW/ref=sr_1_sc_1?ie=UTF8&qid=1466411504&sr=8-1-spell&keywords=soil+moisture+snesor)

I don't know the impedance of this sensor (I have to say I'm new on this matter).

Thanks

How are the pins labelled?

From that page it says:-

Module Output is high level when the soil moisture deficit,or output is low.

And you said:-

the problem is that when the device (for example a soil moisture sensor) is working fine I have similar values than when is damaged, so I cant detect the problem.

If you look there is an amplifier / threshold trigger between the sensor and the Arduino, therefore there is no way you can tell a malfunctioning device from a working device with this setup.

I've seen some modules with both analog and digital outputs, though... I see four pins, that's why I'm asking about the labeling. Nobody should buy anything like that device without documentation.

That's the strange thing about some sites like Banggood and Amazon. Often there are no docs. Still people buy the stuff. Ebay sellers usually try to link you up with something, right on the listing. So you can usually look over the docs before you buy.