Is it possible, using the GPIO Port to power a relay. I have read things about the GPIO port saying it is very easy to mess up, and seeing that activating a relay (basically a short circuit through a magnetic coil) scares me a bit. I want to be able to turn things such as lamps on and off with the raspberry pi and knowing they use 120VAC means I will have to use a relay.

  • Have you tried searching this site for relay. I could do this and post some suggestions, but you would learn more by doing it yourself. I will point out, that while this is possible, there are potential safety issues controlling mains power for the inexperienced.
    – Milliways
    Jan 31 '14 at 11:44
  • I am quite experienced in controlling 120VAC, and I have worked with controlling relays many times before. (Have a bit of a relay stash) I have indeed searched for relay on the site before, and didnt see anything. @Milliways
    – JVarhol
    Jan 31 '14 at 11:47
  • jvarhol I get 90 results in a search
    – Milliways
    Jan 31 '14 at 11:52
  • I got results as well but i couldnt find one that suited my needs
    – JVarhol
    Jan 31 '14 at 11:52
  • Will. Check again though
    – JVarhol
    Jan 31 '14 at 11:53

A relay is an electro magnetic, mechanical switch. You should not power a relay directly from GPIO because relays use allot of power to pull and hold the switches, plus there is risk of feedback that can cause damage to the GPIO. You need to use Diodes to prevent this and have a reliable power source, which the Pi does not really have.

It is easier to buy pre made Relay breakout boards, for use with Arduinos for example since they are built to be driven by GPIO and have all the protection built in while allow low power IO to activate the relays.

You can also look at using high power transistor- but these come with their own pitfalls. They can generate high amounts of heat and they can burn out creating short circuits on your high power- causing more problems. But they are easier to use if you understand how to use the,


I used a module similar to the Sainsmart to control a crockpot.

Controlling a Crockpot with a RaspberryPi

Several internet providers have these modules, really inexpensive.


  • Whilst this may answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – Jivings
    Mar 4 '14 at 6:43

I've had this problem before and although not with a RaspberryPi, the solution is still valid. Because of the high electrical requirements of a relay and the low power output of the GPIO pins, you need to step up the current to power the relay with a transistor. The GPIO pin gets connected to a resistor, which connects to the transistor. I've previously used a 2N2222A to good effect with a 1.5 Kohm resistor. The emitter gets connected to ground and the collector gets connected to the - of the relay. (The + is connected to a sufficiently high current/voltage source to drive the relay. Max 40 V.) Source, page 329.

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.