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


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. – RubberStamp Dec 3 '17 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 Dec 3 '17 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. – RubberStamp Dec 3 '17 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 Dec 5 '17 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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