I'd like to use the GPIO pins on my RasPi to close a circuit. I don't want any power applied to the circuit either from or to the RasPi, just something as simple as touching two wires together to close it.

I thought I would be looking for a relay, but everything I see on the internet about relays is to control high-voltage things with the low-voltage GPIO pins.

  • 2
    Could you please explain what exactly is the problem with using relay in your case? Commented Apr 22, 2013 at 21:55
  • My electronics are a bit rusty, but a relay or maybe even simply a transistor should do. After all, a transistor is an electronic switch.
    – Arne
    Commented Apr 22, 2013 at 23:41
  • 1
    While a relay CAN control higher voltage circuits (and isolate them from the controller), that is not a requirement. Can switch the exact same voltage or lower if desired, and the relay is quite literally like touching the two wires together.
    – Tevo D
    Commented May 24, 2013 at 14:48

1 Answer 1


A relay does exactly what you're saying: it literally closes a connection to complete a circuit. If you want something more low-profile (not necessarily simpler), you could use a transistor, but you have to be careful. The GPIO pins on the Pi run at 3.3V instead if the usual 5V, so if you configure your transistors incorrectly, you could do some damage.

That said, a transistor is probably the best way to do what you're saying, but you have to consider your application. What voltage do you need to control? Is current always flowing in one direction, or does it have to flow both directions? If the current only flows in one direction, you could use a Bipolar junction transistor, or BJT. If the voltage you're controlling is above 3.3V, you're probably going to use an NPN transistor, as shown on this page. Ignore all the arrows on that page, they point in the direction of electron flow instead of current flow, which is just confusing. If you want a lot of current use a Darlington Array, and be careful to not exceed the limits of your transistor(s).

If you need to switch a voltage where the current will flow both directions, you could use a pair of MOSFETs, but relays might be a more common and simple approach. See this answer for more information.

You've probably already found this, but to control the GPIO pins look up the wiringpi library. Good luck!

  • thank you krs013 - I am trying to follow this and am still missing something - I have a 5V circuit that I need to close using a GPIO signal. To create a test environment I've created a board set-up with a LED and a resistor and then added a BC547C NPN transistor downstream of the LED; with this set-up I seem to be able to turn the LED on by connecting the same 5V supply to the base of the transistor (and off by disconnecting it); however - replacing this connection with the GPIO from the RPI doesn't seem to work. I don't know if that's only because the GPIO only provides 3V or something else? Commented Jul 7, 2016 at 10:12
  • 1
    Probably something else. You should only need about 0.7 V to trigger the NPN transistor, so 3.3 V is plenty. As a test, see if the Raspberry Pi can light the LED on its own (Provided it's not blue or white--those might require more voltage. Red is your best best). Also, make sure to have a resistor (1K or greater) on the base, otherwise the current flowing through it might damage the transistor. If you didn't do this when testing it with your power supply, it might have burnt it out.
    – krs013
    Commented Jul 7, 2016 at 16:17
  • Thanks @krs013 - circuit with RPI 5V, GPIO19 a LED and a resistor works well with a simple blinky app. I certainly did not have a resistor on the base initially, have added one later, but it might have been too late :-) - how can I check if the transistor has burnt out? Commented Jul 8, 2016 at 7:39
  • 1
    There's probably an answer on electronics.SE that answers better, but in brief... Your best option is to use a multimeter with a transistor tester mode (it'll have a circle of holes for pins with B, C, and E twice, probably) and measure the beta, which should be 100. If that's not an option, you can test of the base-collector diode junction is burnt out just by using a multimeter's diode tester function between the base and emitter and it should give 0.6 or 0.7 as a reading. My favorite solution is the simplest: find a new transistor and switch it out. If that fixes it, the old was was burnt.
    – krs013
    Commented Jul 8, 2016 at 7:54
  • Thanks again - both used the multimeter and managed to get new transistors and confirm I did ended up with the right circuit with the help of your original process, but along the way burnt my transistor which is why it didn't work. now it does. thanks for the patience :-) Commented Jul 12, 2016 at 22:08

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.