Long wires and float switch problem

I have 2 Over head tank in my house and each will be controlled by a 230V solenoid valve. There are 2 float switches in each of the tank. The float switches are being connected to arduino using pullup with 36ft 1sq.mm wire along with all the household appliances line concealed. Whenever the tank water is reduced, the motor turns on, but suddenly it turns off in the middle of the filling the water and when i reset the arduino, it works like crazy and i dont know what happened. After several resets, the arduino seems to work as normal.

  1. I think this is interference problem but i don’t know exactly what is the proble.
  2. I have uploaded my code if any mistakes please notify me.
  3. I have also uploaded the float switch i am using it is normally open switch.

Motor_Final_Rev.ino (2.47 KB)

float switch.jpg

With that length of wire you might need stronger pull up, like a 1k resistor.
And a 100n ceramic cap from pin to ground.

I assume you have used shielded or twisted wiring for your sensor (Cat-5). Not just twin flex.

Never a good idea to run low voltage wiring next to mains power wiring.
Leo..

I had used a plain 1 sq.mm wire, and i have used a internal pullup resistor.

The diameter of the wire is irrelevant, and I already saw the use of internal pull up in your code.

Internal (weak) pull up is ok for short wiring to a breadboard, but 36ft is like a big aerial.
It picks up lots of interference that you have to kill.
Try adding a 1k pull up resistor (you can leave the code as it is), and the capacitor I mentioned in post#1.
Leo..

Wawa:
The diameter of the wire is irrelevant, and I already saw the use of internal pull up in your code.

Internal (weak) pull up is ok for short wiring to a breadboard, but 36ft is like a big aerial.
It picks up lots of interference that you have to kill.
Try adding a 1k pull up resistor (you can leave the code as it is), and the capacitor I mentioned in post#1.
Leo..

I Will definitely try that and can i use interrupts instead of normal method of sensing the input? Will it be effective than the previous method i tried?

Interrupts will be less effective. They are intended to respond quickly to small glitches - exactly the stuff you are trying to remove. Interrupts are also more complex to visualize and unnecessary for the data you are working with here.

Can i use a 22micro farad electrolytic cap. If not then can anyone please say why because these cap can be used as a bypass cap as mentioned in the wiki.
PS - if i am wrong dont mistake me as i am a newbie. Thank you.

22uF is kind of large but it should work effectively. A more normal number would be 0.1uF or even as small as 22pF (0.000022uF)

100n is common as dogshit.
Get the proper value.
Next you’re posting again that it didn’t work.
Leo…

MorganS:
22uF is kind of large but it should work effectively. A more normal number would be 0.1uF or even as small as 22pF (0.000022uF)

Its risking welding the switch contacts closed, so if you are forced to use it add 100 ohm resistor in series
with the switch to limit the current.

Note that the capacitor must be at the Arduino end of the cabling run, not the switch end.

Wawa:
With that length of wire you might need stronger pull up, like a 1k resistor.
And a 100n ceramic cap from pin to ground.

I assume you have used shielded or twisted wiring for your sensor (Cat-5). Not just twin flex.

Never a good idea to run low voltage wiring next to mains power wiring.
Leo..

Even after using capacitor, arduino still switches off the motor when i turn on my fan or turn it off. Is there any other way. Thank you.

Hi,
Can you please post a picture of your project?
So we can see your component layout.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

Sounds like the EMI coming down the wire is common-mode (big pulses induced off the mains).

Some software debouncing is in order, just like for any button input.