I should mention that I am trained in biochemistry with a basic college-level physics background, but with no background in DIY electronics.

I'm trying to make my Raspberry Pi control a simple valve. There are many similar threads, but I couldn't find anything to solve my issue. My circuit is set up the same way as this guy: http://www.davidhunt.ie/water-droplet-photography-with-raspberry-pi/

Specific parts:

The problem is simple - the solenoid valve doesn't move when I tell the pi to make it open. I think I set up the diode and transistor correctly (diode line mark on positive side and transistor base/collector/emitter from left to right).

To check the circuit setup, I replaced the valve with a 1k resistor + LED in series, and it turned on and off as desired. When I directly attach the solenoid valve to the 12V power pack it opens just fine.

Is there some issue with the amount of current going through the valve? I don't really know what else to try with troubleshooting. I can take a picture of the breadboard setup tomorrow if needed, but if the circuit wasn't set up correctly, then I don't think the LED would've worked?

Finally - on the second or third time I was swapping the valve with the resistor/LED, right after I unplugged the positive/negative wires leading to the resistor/LED, the Raspberry Pi turned off. !!! But now it appears to be (temporarily?) bricked and the red power light doesn't even turn on when it's plugged in. I am not looking for solutions to this per se but it might be useful information so I'm mentioning it.

edit: I solved this by adding a second 1k resistor in parallel with the first. Transistor is still TIP31C.

  • Hello and welcome to RaspberriPi.SE If you are for whatever reasons not satisfied with the answers to your questions try also electronics.stackexchange.com for such electronics issues. They are a vivid community too.
    – Ghanima
    Commented Dec 8, 2014 at 9:11

1 Answer 1


Your solenoid is 2W

For 2W and 12V

2/12 = 0.166A

or 166mA

The TIP31C is a power transistor, but only has a current gain of about 10

That means your GPIO pin would need to supply 16.6mA to the base. This exceeds the PIN rating, but isn't possible anyway as you have the 1k resistor there. If you measure the voltage across the solenoid when it is supposed to be on, you'll see you get less than 12V across it

A "small signal" BJT transistor can typically switch 500mA and might have a current gain of 200 which is more likely to work with a GPIO pin.

Alternatively you could use a MOSFET instead of a BJT, but take electrostatic precautions when handling it.

  • Thanks, that's helpful. Not sure if it makes a difference, but it's a TIP31C, not TIP41C. (How do you know the current gain? Looking at Figure 1 here it looks like the current gain is around 100 for a collector current of 200 mA, but later on they use a value of 10.) I read that the GPIO pins are designed for 3 mA output but have a max of about 20 mA - but the 1k resistor cuts down on this? Would a 2N2222 work? 40V and 800 mA Commented Dec 8, 2014 at 16:08
  • 1
    Sorry, TIP41C was a typo. To get the maximum drive from GPIO pins you need to make some extra setting. Yes a 2N2222 should be a good fit. Commented Dec 8, 2014 at 21:21
  • When I used the 2N2222 it still didn't work. I also think the transistor burned out between the base and collector pins. After about 10-20 seconds of running, I could smell something burning, and then after that the valve would open when attached to collector/emitter even with nothing plugged into the base. Commented Dec 10, 2014 at 0:11
  • After that I had some sudden insight and after a little fiddling I decided to attach a second 1k resistor in parallel with the existing 1k resistor, and everything works with the original TIP31C transistor. Commented Dec 10, 2014 at 0:12
  • Sorry to hear about the 2N2222. It's possible it wasn't turning fully on (no enough base current), which could cause it to get quite hot. Another possibility is that the diode was not connected properly. That would cause a large voltage across the collector and emitter when the solenoid turns off which can destroy the transistor. You should measure the voltage across the TIP31C to make sure it's turning on hard enough. Wire the diode as close to the solenoid as possible. Commented Dec 10, 2014 at 0:41

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.