One telephone wire is +5V.
Another wire is floating and it connected to microcontroller.
When both wires touches each other, Micro-controller reads the signal and switch off the motor and switches ON an led for indication.
Everything was working good until the telephone cable is of shorter length. But my overhead tank is located far away. So i have to run 40meters of telephone cable.
When i run the cable for 40meters, and i power on the instrument, motor runs for some time and switches off automatically and led glows. Why is it happens only if i run the cable for long distance?
I agree, the problem is interference being picked up on the wiring, it is enough at times to turn the transistors on and produce a fake reading. Personally, I would increase the collector resistors around 22K and add resistors of about 100K from the bases to ground. If you are in a high RF area (close to a radio station or mobile phone) it would be a good idea to add capacitors of say 1nF between the bases of Q1 - Q5 and ground as well.
You must be aware of variations that can occur on water resistivity depending on factors such as its own temperature or even on concentration of diluted ions.
Probably some other conditions may be affecting measurements, than not only cable length.
for long distances +5V is not a good idea. The voltage must be more, and since even this may pickup noise, you also may have to drive higher current into the lines....
Of course in addition to the noise problem, there may be other factors as andre_teprom pointed out...
Expectable Problems with a strange Tank Level Switch
I'm tempted to say that a tank level sensor using DC current is a bad design from the start because the current will slowly dissolve the electrodes by electrolysis. But probably it will work for a considerable lifetime. I would also prefer pull-down resistors giving a defined threshold for the inputs and filter capacitors across base-emitter terminals to block RF interferences.
But I guess you can stay with the poor hardware design, leave everything as is and simply go for software filters that only accept a low or high level if it's constant for a certain time, e.g. 100 ms.
The sensor must be capacitively coupled to avoid DC current flow. And I don't see how the circuit is "measuring" or discriminating sensor capacitance values.