I've created a sort of sensor to detect whether the water level in my aquarium is too high or too low.
Hardware part:
See this schematic for how it works:
So the red part floats on top of the water, if the water is getting low it goes down, if the water is high it goes up. The black part is on the ground and never moves.
When the water is getting low, the red part (and thus purple) goes down connecting pin 21 to ground.
Software part:
If pin 21 is connected to ground I switch on a pump using a relay and when the water level has risen enough pin 17 gets connected to ground, and I switch off the pump.
The code I use to detect whether pin 21 or pin 17 is connected is of this form:
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
and in some loop I check:
isConnected = GPIO.input(17)
My problem:
This used to work well, but lately the pump doesn't switch off anymore when pin 17 gets connected.
What is wierd though is: when I manually push down the red part for a moment (breaking the connection of pin 17) and then let it connect again, the pump shuts off like it should.
Could this be a power issue? Or maybe I need a pull up/down resistor?