I'm exploring various ways to detect higher voltage using the Pi and have come up with a circuit where the 5v would energize the coil of a relay which would switch 3.3v from the Pi's internal 3.3v supply pin to a GPIO pin.

The 5v will be from a standard wall adapter rated for 1amp and will only be on for brief periods 20-30m weekly.

Is this a viable circuit?

I'm mainly concerned about the load on the GPIO pin - do I need a resistor to limit the current from the 3.3v supply?


simulate this circuit – Schematic created using CircuitLab

2 Answers 2


Why not just connect Pi ground to one relay contact and a GPIO set as an input to the other. Then set the internal pull-up GPIO resistor. The GPIO would then read high when the relay is open and low when the relay is closed.

You need no other circuit components.

  • On the Pi side, the simple connection should be just fine... However, there needs to be a protection diode in parallel with the relay coil on the input side. Commented Dec 3, 2017 at 22:54
  • @RubberStamp Is there anything to protect on the relay coil side? It's switched by the wall wart which I didn't think would be affected by back EMF from the coil.
    – joan
    Commented Dec 3, 2017 at 23:04
  • Without looking at the schematic of the power supply, there's no way to know if the diode is needed or not. If it's unknown, the diode should be included. Commented Dec 3, 2017 at 23:32
  • I was definitely overthinking this problem. Thank you for the simple and elegant solution. One thing I found was that the internal pull-up was being a bit unreliable so I used an external one.
    – nageeb
    Commented Dec 5, 2017 at 20:56

I have about the same question. I have a 220V relay to be connected to a raspberry pi input via the contacts. One of the contacts is already connected to a 5V supply. Do I need a resistor to connect to a GPIO input?



  • The answer section is for answers. This should be a question unto itself.
    – james6125
    Commented Sep 18, 2023 at 0:52

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.