Ok, I don't know anything about transistors, and my knowledge about electronics is basically limited to U = R . I and Don't put this cooper wire in the 200V outlet if you wanna live.

I read several articles/tutorial/stackexchange posts about this question, without understanding how I could apply this to my situation.

My situation :

  • I have 3 wires :
    • A ground
    • A +5V direct current
    • A digital output, sending either 0V or +3.3V depending on what my Raspberry Pi's code is currently doing.
  • I have a solenoid
    • I want my solenoid to receive +5V when my digital output sends +3.3V, and 0V when my digital output is sending 0V.

If I understand correctly, it seems that I could use a transistor to achieve this. And I have a vague idea of what my electrical network should look like, something like :

  • Collector plugged on +5V
  • Base plugged digital 0V/+3.3V
  • Emitter plugged to solenoid
  • Other end of soneloid plugged to ground.

(Am I wrong ?)

The most mysterious mysteries are :

  • Which particular transistor should I use ? Right the only ones I have are little, blacks, with 2N 3904 -H48 written on them (no idea about what it means).

  • Should I add a resistor some where, like ... to prevent things to burn ?

  • Is transistor really what I need ? Or am I totally wrong on this point ?
  • 3
    \$\begingroup\$ With that sort of knowledge on electronics, before attempting this please learn the basics. For one, this question has been answered dozens of times, there are so many example circuits on google, and if you have difficulty understanding them, or difficulty knowing what to search for, then you need to step back, start at the beginning, and learn simple circuits before advancing, just like everyone else here did. I am not saying this to be rude, but there are fundamentals that really should be understood before trying to design circuits. \$\endgroup\$
    – MCG
    Feb 12, 2019 at 16:37
  • \$\begingroup\$ What MCG said. In addition, it's worth mentioning at least that the transistors you have are 2N3904 transistors; the -H48 is irrelevant (EE is my profession and I still don't know what the extra bits on part numbers mean half the time so don't worry about it) \$\endgroup\$
    – Hearth
    Feb 12, 2019 at 16:39
  • \$\begingroup\$ Ok ok. Guess I will calm down and ask my boss to hire and electrotechnician. \$\endgroup\$
    – Motiss
    Feb 12, 2019 at 16:46
  • \$\begingroup\$ I will add, if you have to know just two things about electricity, Ohm's law and "don't mess with mains voltages" are probably the top two. Not necessarily in that order. \$\endgroup\$
    – Hearth
    Feb 12, 2019 at 16:55
  • \$\begingroup\$ use the first scheme (schematic), but use a NPN power-Darlington bipolar (named after Sidney Darlington), and place a 1,000 ohm (Brown-Black-Red) resistor between your 3.3v logic output and base-input of the Darlington. And don't forget that diode across the relay coil ---- a BIG diode, not a "signal diode". \$\endgroup\$ Feb 12, 2019 at 17:22

1 Answer 1


The basic idea is correct, but I am sure that you can find that info with a quick search...

Transistors (let's say BJTs) working at saturation/cut-off region, work as switches. When in saturation (Base = "HIGH") they let current through them and when in Cut-Off (Base = "LOW") they block the current. So you can make an equivalent schematic just like that


simulate this circuit – Schematic created using CircuitLab

The diode in the third circuit is called flyback (or freewheeling) diode and is mandatory in order to protect your transistor when it switch from on to off.

Now, selecting the transistor in this case is pretty simple. Basically any transistor can handle the 5V of bias (when it is off, the voltage drop across it is 5V), so it depends on the current the solenoid needs to operate. Eg. if it needs 500mA, use a transistor that can handle >500mA \$\rightarrow\$ 1A.

In any case, before proceed with your circuit, you have to study/search the basics of the passive components, transistors and micro-controller Input/Output (IO). Otherwise you may start burning things and don't understand why.

  • \$\begingroup\$ Ok. Thanks for your help. Previous answers lead me to understand that it was merely feasible with my lack of knowledge, but I'll try to do something with your schemes. \$\endgroup\$
    – Motiss
    Feb 12, 2019 at 17:15
  • 1
    \$\begingroup\$ There should be a resistor between the GPIO pin and the transistor base, otherwise you'll make the processor unhappy. The voltage from pin to base will be 2.6V (3.3V - 0.7V), and you need to size it to flow about 1/10th the current that your solenoid needs. If the solenoid needs more than about 500mA (the limit for the 2N3904) then you need a different transistor -- and please check a data sheet for a 2N3904; I'm not sure I'm remembering the rated current correctly. \$\endgroup\$
    – TimWescott
    Feb 12, 2019 at 18:11
  • \$\begingroup\$ The diode in the third circuit is known as a flyback diode, not a flywheel diode. \$\endgroup\$
    – Pzy
    Feb 12, 2019 at 19:24
  • 1
    \$\begingroup\$ @Pzy It's also known as a freewheeling diode. It may be the combination of seeing flyback and freewheeling that has somehow created the chimera, flywheel? \$\endgroup\$
    – jonk
    Feb 12, 2019 at 19:44
  • \$\begingroup\$ A 1N4148 might not be a suitable diode, either. Consider a 1N400x instead. \$\endgroup\$
    – Hearth
    Feb 12, 2019 at 21:06

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.