bit of an amateur looking for some advice. I looked at the other question concerning my problem but i didn't find what i was looking for.

I need to switch ON and OFF a solenoid valve using my RPI. I found quite a lot of design.

But i can't decide on using a transistor like this design :

solenoid valve using transistor

or using a relay :

solenoid valve using relay

Can you tell me if the design are correct and what's the advantage/default of each one ?


PS : i will use this valve


2 Answers 2


Both designs will work and its downto what current the TRANSISTOR will see and what supplies are being used.

enter image description here

In this topology the main BJT will sink 3Amps and thus the source to the BASE will need to be capable of driving TBD mA into it to ensure conduction. The Transistor will dissipate more power

enter image description here

In this topology the current the BJT has to sink is considerably less and it is purely the energising current of the relay. However, you need to source a relay.

The 1st is advantageous from a partcount but the 2nd is advantageous from a power dissipation in the BJT and thus current sourcing capability from the GPIO pin.

An improvement could be to use a FET instead of a BJT as the gate drive requirements would be less.


There is a 3rd option and that is using the 1st topology, with a FET but PWM the FET. Solenoids have two current requirements

  • Pull-in
  • Hold

Pull-in is ALWAYS higher than hold as it has to produce enough magnetic force to close the airgap and move the plunger. Hold is lower as you need less amp-turns to produce the same MMF with a vastly smaller airgap. Thus you can have higher duty for PWM (ie higher current) and lower duty for hold (ie lower current == lower losses)

HOWEVER, this is dependent on alot more infomation about the solenoid: change in inductance, current change.

  • \$\begingroup\$ It is also possible to cascade transistors to increase the gain (less current sourced from the RPI) and split the thermal load. Relays are only nice when isolation and both current directions are required, but even this can be replaced by an optoisolator and transistors or a triac (that's what solid state relays are). \$\endgroup\$ Commented Feb 17, 2015 at 13:07
  • \$\begingroup\$ yup. I have added in a comment about supplies because if they are on split supplies then a relay is almost implied. \$\endgroup\$
    – user16222
    Commented Feb 17, 2015 at 13:16
  • \$\begingroup\$ thanks for the complete answer . I think i'll pick the 2nd solution. I i use this relay :amazon.com/2pcs-Power-Relay-SRD-12VDC-SL-C-Type/dp/B00MPEUPUE Ic = (5V-0.2V)/~100Ω = 48mA . For 2N2222, Hfe min = 30 I think so Ic / Hfe so : 48mA / 30 = 1,6 mA 5mA will be enough for the 2N2222. Rbase = (3.3V - 0.75V)/5mA = 510Ω. Are my calculs correct ? \$\endgroup\$ Commented Feb 17, 2015 at 13:29

Omitting the relay is likely to be a cheaper solution. To choose an appropriate transistor requires some details about the solenoid in the valve. What current does it draw at steady state and the peak switching current at startup?


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.