Electronic – How to avoid input floating ports on a microcontroller

microcontroller

I have 16-bit Thunderbird12 Microcontroller, similar to the Freescale 68HC12.

I'm currently working on a project to monitor and control the level of water. Everything is working fine except for the input ports which have floating pins and they are randomly reading low and high. I did some research here and found that pull-up or pull-down resistors are the solution, but my set up is different.

There are 5 "sensors" that feed into the input ports. Each sensor is connected with 2 wires; one wire goes into the pin, and the other into VCC, then both are inserted into the container with both ends exposed. When the water level goes up, it touches both ends and completes the circuit and setting the input to 1.

The problem I have is that the input pins still read High even if the wires are not connected yet. What can I do do prevent this high impedance? I can't ground the wires or set them to 1, because the latter is supposed to happen only when the circuit is completed (when water touches them).

Any help would be appreciated, thank you!

Best Answer

You still need a pull-up or pull-down resistor as appropriate. If the sensor connects between Vcc and the input pin, and if the sensor is open-circuit when off, then it would be a pull-down resistor. If the sensor connects between ground and the input pin, you need a pull-up resistor.

The resistor needs to be chosen so that it has a substantially higher resistance than the sensor.