this solenoid is killing me! I have it connected to a GPIO pin, and I've tried running it both from that to 3.3v, and to GND. Either way, with Low or High written to the pin, respectively, it doesn't work. In either situation, an LED in the solenoid's place in the circuit does turn on. The solenoid works when connected from 3.3v directly to GND.

What am I doing wrong? Help!

  • 2
    Seeing your code, and knowing what GPIO pin and solenoid you are using would help. Commented Dec 9, 2013 at 16:35
  • Pin 17 from the cobbler. I don't have the pi or solenoid on me right now so I can't get the code, but I basically took a blink script and plugged the solenoid in instead of an LED. The solenoid is small, like I said, it runs off the 3.3v rail from the pi. Commented Dec 9, 2013 at 16:59
  • What are the specs for the solenoid that you are using? Commented Dec 9, 2013 at 17:24
  • Are you wiring your Pi to the solenoid as this example shows for an Arduino? playground.arduino.cc/uploads/Learning/solenoid_driver.pdf Commented Dec 9, 2013 at 17:43
  • 1
    The current from the GPIO pin most likely isn't sufficient to drive the solenoid directly. I recall that the max current from the GPIO pins is 40 ma or in that neighborhood. Commented Dec 9, 2013 at 17:45

2 Answers 2


According to this posting the 3.3v supply comes directly from the power supply on the Pi while the GPIO pins come from the BMC chip and can only supply a limited amount of current. That can explain why your solenoid energizes when connected to the 3.3v supply and not from the GPIO pin.

I suspect that you need to wire the solenoid as shown below (which is from here for an Arduino) except using the Pi GPIO pin instead of the Arduino Digital out. You might need to adjust the R1 resistor value to compensate for the Pi's 3.3v GPIO voltage instead of the Arduino's 5.0v.

This diagram shows using a transistor as a switch to have an external power supply energize the solenoid. The example I took this from used two 9v batteries in series as the external power supply.

enter image description here

Here's another example of using a transistor to switch on an external circuit from RPi GPIO Interface Circuits. The web page says that the 5v power supply shown can be any voltage up to 40v which the 2N3904 can support. The page says that this circuit is suitable for up to 100mA of current.

enter image description here

  • Could i get away without using the diode from that circuit diagram? Commented Dec 10, 2013 at 3:32
  • 2
    unless your solenoid is very small and your transistor is very large and forgiving, you'd better use diode: en.wikipedia.org/wiki/Flyback_diode
    – lenik
    Commented Dec 10, 2013 at 4:18
  • 1
    Yes, according to @lenik's Wikipedia link, without the flyback diode an arc of electrons can occur either across the switch or transistor in the circuit. Evidently the energy that gets stored up in the inductor needs a way to dissipate and the diode allows that to happen when the transistor opens. Commented Dec 10, 2013 at 15:24
  • I wired it like that, and it worked to light up an LED but again when I put the solenoid in the LED's place, between the 5v and the c end of the transistor, it didn't activate. If I connect the transistor-facing lead of the solenoid to the ground, it activates. I tried wiring it this way to an arduino, too, and the LED would light up there but the solenoid wouldn't activate. Commented Dec 10, 2013 at 20:04
  • What transistor did you use? When you attached the LED did you also use a resistor? If not, why didn't the LED burn out? i.e. what limited the current through the LED when it was connected to the transistor? Commented Dec 10, 2013 at 20:20

I would connect the solenoid up through a small old-fashioned mechanical relay, then you can apply as much power as you need to the solenoid, with the advantage of electrically isolating the Pi from it. Example of wiring is shown here.

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.