I have a standard float switch in a remote water reservoir connected to a normal electric cable (100m+ long). I want to check with a raspberry pi if the float switch is on (i.e. water level is low) or off (i.e. water level is okay) and based on that control a relay switch.

Is there an easy way to detect if the switch is on or off with a raspberry pi? I presume I cannot simply connect it to the GPIO pins as it is a float switch that is meant to automatically disconnect a mains circuit?

Update1: The float switch looks like this and thus simply disrupts a mains electricity signal float switch

Update2: I prefer to use this existing float switch as it is already in place in the reservoir and the 100m+ cables are in place under ground. It was connected to the mains and would automatically disrupt the power to a pump, but I want to have a raspberry pi in-between. So I guess the question can be rephrased to: in what way can one measure if current can flow through a mains wire with a raspberry pi?

  • 1
    Please show us what kind of switch you're using. How is data transmitted, is it through the electric cable?
    – user96931
    Commented Mar 23, 2020 at 18:32
  • 1
    Do you have a way of measuring the resistance through the 100m of cable and the switch with the switch closed?
    – Bob Brown
    Commented Mar 23, 2020 at 19:32
  • Ah, let me see. The float/flow switch that disconnects nearby AC mains is simple. If you want to control things far away, say 200m, then usually the industrial and or EE guys would recommend reed switch type devices. The reed switch usually connects to a low voltage, say 5V/12V/24V DC. And this DC high/low (0V, 5V) signal can transmit long distances. Of course long wiring acts like an antenna can pick up noises. EMI etc. But like transient switch bouncing etc, you just use software to filter them. You can double shield cable (or even differential/ twist pair) to reduce noises / to continue,
    – tlfong01
    Commented Mar 24, 2020 at 1:56
  • So you can of course use Rpi GPIO to deal with DC 0V/5V/12V signals. An example of read switch is the following: References: (1) "Float Level Switches & Sensors with Magnetic Reed Switches - Sems Sensors": gemssensors.com/level/single-point-level-switches/float. Cheers.
    – tlfong01
    Commented Mar 24, 2020 at 1:59
  • And if wish to also detect/ control AC mains at the far side, then things might become a bit complicated. You might like to skim the follow Rpi flow meter project forum discussion to get an idea of the difficulties encountered: Ref (2) "Flow meter with 5V reed switch - rpi.stackExchange": raspberrypi.org/forums/…. Cheers.
    – tlfong01
    Commented Mar 24, 2020 at 2:07

1 Answer 1


Buy a cheap relay and connect it to the main circuit. And then use one of the normal open contacts of the relay to connect to the raspberry pi, then treat it as a button?

  • 1
    Could you be more specific? i.e. how to connect, what main circuit, what normal open connects, and how to treat it as a button? I look forward to your elaboration! Note I already have a relay HAT on my rpi, is there a way I could use that?
    – crazjo
    Commented Mar 25, 2020 at 8:33
  • Is the pump still attached? By saying you want to put the pi in-between, I presume the float switch is still controlling the pump. You’d need to purchase a relay with the same coil voltage rating as the pump. Then, you connect the coil of the relay in parallel with the pump. After, you can use the normally opened contact and the common terminal of the relay (it’s essentially just acting as a switch) to connect to the pins of your raspberry pi. Here’s a link that shows an anatomy of a basic relay: d114hh0cykhyb0.cloudfront.net/assets/2016/07/21151153/…
    – Fernando
    Commented Mar 26, 2020 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.