I am thinking of the cheapest water leakage sensor (0 $). I would like to share my idea and get feedback on its feasibility.
Here's a brief explanation:
I will be using an esp8266.
Configure one GPIO pin as INPUT and another as OUTPUT .
Connect cables to the GPIO pins.
Place the end of the cables into an empty glass.
Create a loop in your code that alternates between setting the OUTPUT pin to HIGH and LOW using digitalWrite.
Continuously read the voltage on the INPUT pin using digitalRead within the loop.
When water is poured into the glass, it will (would) create a conductive path between the cables, allowing current to flow. This will result in a change in voltage at the INPUT pin, indicating the presence of water.
I am waiting for your comments and advice. Thank you.
This is basically how moisture detectors work.
There is a basic problem with it in that as the polarity is always the same corrosion builds up on the wires. The way round that is to alternate the excitation voltage using a H-bridge or an AC voltage.
Note pure water is an insulator. Water with salts in them will conduct. Salts not just salt. So dissolved minerals.
May be - may be not - I don’t know but was willing to give the benefit of doubt to OP as his ask was not do any coding. Also if that was the teacher’s instruction, why would OP ask if that can work?
Anyway it’s calling just for a yes or no it would work. So I don’t see answering « it will work if you get non pure water in the glass » as doing a homework for him.
Most of us have worked or seen this problem many times, this is probably the OPs first and without experience he did the correct thing and asked the question. If it is homework he should have mentioned it but that is not a requirement on this forum as I understand it. In my opinion the only bad question is the one that does not get asked. To get past the corrosion he could alternate between input and output pins as well. That would constantly reverse the current flow. That would be a lot less work then an H-Bridge or equal.
I think that the idea is not viable, because in fresh water the value read by digitalRead() will never reach a high level - that is, the sensor will not work.
In such a detector, the electrode potential will be no more than fraction of volt, a signal amplifier is needed to detect it, arduino will not show anything.
Something like this would be easy to setup and test and adapt to use an Arduino analog input.
Could use a super-bright LED and higher resistance and/or higher gain transistor for more sensitivity.