I have my GPIOs doing PWM with pi-blaster.

Now I just need to figure out the wiring. I checked over electrical engineering, and found this question: https://electronics.stackexchange.com/questions/213914/using-mosfet-as-switch, but it hasn't helped me.

I also read through this: http://bildr.org/2012/03/rfp30n06le-arduino/

Anyways, this is, to the best of my knowledge, how I'm supposed to translate the links above into something real:

enter image description here

The issue is, it's not working. What needs to change in this diagram for it to be functional?

P.S. Please don't tell me to go over to Electrical Engineering, the expected baseline of knowledge there is way above this pi hobbyist's education.


4 Answers 4


I just want to post this here to help other absolute beginners like me. The circuit above is correct and imperfect. But if it isn't working, here are some cases to check:

My issue was the breadboard being finicky. If a single connection point on a breadboard is at the whim of chance (as in you have to wiggle it a bit to get a connection), then that's the chance you won't have a working circuit. Those chances compile too.

But also, if you're trying to get a circuit like this working, it is important to read the answer above about getting the right MOSFET. What matters most in a scenario like this is the minimum threshold being below 3.3V. Also, use an N-Channel MOSFET.

Finally, it is good practice (as said in the answer above) to have a resistor connecting the Gate and Source. I'll update this later with the resistor type that I know works (once I've found it). I believe it's because connecting these helps ensure that the MOSFET defaults to off if something goes awry.


Most MOSFETs will not work with the RPi at all; the ones that do will not work well. Here are the issues:

  1. Most MOSFETs require gate-source voltages (Vgs) that exceed the 3.3V output the GPIO is able to provide. These will not work at all.

  2. The MOSFETs with Vgs ratings in the 3V range will suffer from one of the following:

    • They have very low power ratings, OR

    • The gate capacitance will be large; this will tax the GPIO's ability to source or sink enough current to turn the device ON and OFF in a reasonable time.

OTOH, bipolar transistors work quite well with the GPIO's limits. They will switch useful amounts of power with lower losses, and at lower component cost. I can't say that there is no RPi project that would benefit from or even justify the use of a MOSFET, but I will say that I'd really like to see one.

Your drawing doesn't show a load... presumably you want to switch current through some device, and control that with a GPIO on your RPi. If you can give us more information, we'll try to provide a definitive answer.


Do not put the resistor between gate and source when using a N-Channel MOSFET, that is wrongly given in a lot of places on the web. But why; it reduces the drive to the gate of the MOSFET by dividing the gate drive voltage. With a pi and 3V3 your choices are very limited on parts to start with, however it is getting better. You need a MOSFET that turns on at about 2V or less so it is reasonably well enhanced at 3V3. The pull down resistor should go to the port pin and ground not the gate and ground.

The reason for this resistor is most microprocessors/computers have there outputs tristated until they get initialized and the output set to the proper point. During this time the port pin can drift wherever and turn the MOSFET on, sometimes partially destroying it. This generally is not wanted. If you want it on then pull the port pin up to 3V3 otherwise use a pull down from the port to ground.If you put a 10K pull down at the gate and a 1K from the port you now have 3.0 volts on the gate, not 3V3. I use something between 25 and 50 ohms to keep the gate drive solid.

I can understand the confusion. First and most important thing about MOSFETs is all voltage reference points are to the source. Normally P-Channel is for Positive switching and N-Channel is for negative switching. To turn on a MOSFET you see such things as Vgs. This is (Voltage Gate Source) It is positive for N-Channel devices and negative for P-Channel devices. The gates have a maximum Plus and minus rating, anything in that range referencing the source if fine.

Lets try this, your circuit shows a MOSFET where the Pi gives it voltage from the port pin. The source is connected to ground of the PI and its external power supply, this is correct. When you turn the port pin on it will place 3V3 on the gate. If it is not sensitive in that area (Vgs) to high it will not turn on, that is the way it was designed. If say it needs 2V it will turn AOK. Note we are referencing the ground (source) for these voltages.

Now the same thing with a P-Channel MOSFET. In this case the source is connected to +. If the previous holds true you need a negative voltage to turn it on. First thought now I need another supply, not true. Remember the source reference, guess what the ground is - in reference to the source so it will turn on if the gate is grounded.

When you purchase MOSFETs get the ones that are rated for avalanche energy. They are designed to conduct a lot of current for a short period of time. When you switch an inductor on you store energy in the coil, when you turn it off that energy comes out as voltage. But it does a funny thing it changes polarity and will rise until something stops it (Ignition coil). Two common approaches is to place a diode across the solenoid to dissipate the energy (it needs to be rated to handle the coil flyback current). The diode will turn on and limit the voltage to about -0.7V until the energy is dissipated. This is a short high current pulse. An avalanche rated MOSFET by its very geometry has a substrate diode (it is shown in the simble) that happens to point in the correct direction. This will behave like a flyback diode but it is resistive in nature so the flyback voltage can vary. I use the RDSon x 2 when calculating the current and voltage.

Hopefully this helps you understand what is happening. They are great parts if used properly.

  • Frankly your first paragraph is WRONG! While I agree there is no need with a CMOS driver it is included to protect the circuit and discharge gate capacitance when there is no drive e.g. if the GPIO is an input. Also a sensible resistor will have negligible impact - there is NOTHING to "divide".
    – Milliways
    Commented Oct 19, 2022 at 5:13
  • May I have a question about the first paragraph? What is the difference between connecting it to the port and ground vs the gate and ground? The port pin is connected to the gate, so the only difference should be the wire resistance, which is imho negligible in the context of a 100k resitor. Commented Feb 16 at 22:14

You have not specified what MOSFET. Most will NOT switch reliably with 3.3V.

There are a few models which will work.

NOTE You should check the SDG, as there is no standard.

You should ALWAYS include a resistor (~100kΩ) between G and S.

See http://elinux.org/RPi_GPIO_Interface_Circuits#Using_a_FET

  • The MOSFET I have is correct. It is meant for 3v3 to 5v. Are you saying the thing I'm missing is a resistor between G and S, and that is it? I tried that to no avail.
    – Seph Reed
    Commented Aug 9, 2017 at 1:52

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.