The simplest way, from a do-it-yourself perspective of someone that has to ask for circuit advice here, to detect water is a float switch. These will be available in most hardware stores around where they sell sump pumps. Complete sump pumps come with a float switch, but they are often available by themselves as replacement parts.
To do this electronically is more complicated. I've had to detect water water before, and a good method is to have two sensors connected to pins of a microcontroller. However, you don't just check for resistance between the two electrodes. There are several issues with two electrodes you have to consider:
- Electrolisys. You want to avoid passing any large current and any net DC over time.
- Corrosion. This changes the resistance, can cause assymetry, and a battery effect.
- Common mode noise.
The way I deal with these issues is to take four separate measurements for each over all reading that is intended to indicate the presence of water. Each electrode is driven strongly high and low. At the same time the other is driven weakly the opposite direction while its voltage is measured. This comes out to a total of 4 measurements that result in no net DC voltage. Do the math and you will see this also cancels out common mode noise, bias caused by the battery effect, and assymetric resistance caused by corrosion.
One set of readings only takes a few 10s or 100s of µs to make. If you only need to know the presence of water every 1 second, for example, then the electrode can be off most of the time. This saves power and reduces corrosion due to electrolosys.
The microcontroller then decides whether water is present or not, and drives a relay accordingly.