Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

MOSFET for Raspberry Pi
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MOSFET for Raspberry Pi

by axertion on Fri Apr 28, 2017 12:38 pm

Hi all!

I'm using a basic circuit to trigger a 12V Push-Pull solenoid using an Arduino UNO.

The circuit I'm using as a reference is this: http://bildr.org/2012/03/rfp30n06le-arduino/
Image

It works perfectly with the 5V GPIO pin on the UNO, however swapping out the GROUND and GPIO pin to a Raspberry Pi's 3.3V GPIO doesn't trigger the solenoid.

I'm using this MOSFET:
https://www.amazon.com/gp/product/B01GN ... UTF8&psc=1

I asked Adam (the creator of the circuit I'm following) as to why this isn't working, and he suggested that I use this MOSFET instead.

Adam's response about my issue:
MOSFETs are triggered by voltage, so it isn’t surprising that it won't work with 3.3v because this was set up to use 5v. I checked the spec sheet and it looks like the MOSFET can trigger at as low of 2.5v but people on other forums are saying it won’t fully trigger at 3.3v.

I don’t have any experience at all with using MOSFETs with the pi, but I googled it and found this: https://www.adafruit.com/product/355 - Adafruit is claiming that this transistor would work for your needs


Before I buy this MOSFET, I want to make sure that it would actually work with the 3.3V GPIO pin on the Raspberry Pi.

Can anyone here confirm that the IRLB8721PbF MOSFET sold by Adafruit will actually work with PI, assuming I just drop it into my circuit above?

----
A side question. Would it be possible to step-up the 3.3V GPIO signal to a 5V signal to trigger the MOSFET as an alternative solution?

I'm a complete beginner at this stuff, so any insight would be helpful! Thanks!
axertion
 
Posts: 11
Joined: Tue Nov 06, 2012 11:49 am

Re: MOSFET for Raspberry Pi

by adafruit_support_mike on Sat Apr 29, 2017 4:16 am

That one will have the same problem you've already experienced. The IRLB8721PbF needs 4.5v to turn on completely.

You can sidestep the problem by adding an NPN transistor:

relay-driver.jpg
relay-driver.jpg (14.11 KiB) Viewed 2590 times
The 10k pull-up to 12v will turn the mosfet on completely. When you send the RasPi's GPIO pin high, it will turn on the NPN, pulling the mosfet's gate to 0v and shutting it off. Sending the GPIO pin low will turn the NPN off, letting the mosfet's gate rise to 12v again, turning it on.

NPN transistors only need 0.6v to turn on, so they're easier to use in 3.3v circuits.

adafruit_support_mike
 
Posts: 61124
Joined: Thu Feb 11, 2010 2:51 pm

Re: MOSFET for Raspberry Pi

by zener on Sat Apr 29, 2017 1:04 pm

Mike's circuit is correct of course.

But, while I don't want to nit-pick here, the product listing for the AF mosfet does state:

The threshold voltage is also very low, less than 2.5V so you can control it directly from a microcontroller running on 2.8V, 3.3V or 5V logic.


Maybe that needs to be revised?

Personally I think that either fet should be able to do what you are trying to do. Obviously you are proving otherwise. I would verify the voltage between the gate and source pins ON THE FET is actually the 3.3V you think. Also, I am guessing your solenoid does not draw that much current. Maybe I am wrong about that.

zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: MOSFET for Raspberry Pi

by adafruit_support_mike on Sun Apr 30, 2017 3:01 am

The product page is quoting the datasheet's Vgs(th) value, which is one of the more misleading mosfet specs.

It's the point where the mosfet's channel resistance drops from "a few megohms" to "less than a few megohms". The 'Conditions' column just to the right of the values lists Vds as equal to Vgs (2.35v max) and the current through the channel as 25uA. That puts the worst-case channel resistance at about 94k.

I generally start looking at the Rds spec instead, specifically at the conditions where they occur. In this case, the channel resistance goes below 9mohm whne Vgs is 10v, and below 15mohm when Vgs is 4.5v.

Then I skip down to the performance graphs and look for a plot of Rds versus Vgs, which the IRLB8721PbF datasheet does have. It shows Rds dropping sharply when Vgs is 4v, then tapering out as Vgs goes to 10v.

There's also a plot of Id versus Vgs that shows you can get up to about 3A when Vgs is 3v and Vds is more than a couple of volts, but that's pulsed current. Those are always much higher than the continuous-current value for the same Vgs. Taking the ratio of continuous to pulsed current from the Absolute Maximum Ratings table (about 4:1), I'd guess you can get maybe 750mA of continuous current when Vgs is 3v.

The product page does kinda gloss over the details. I'll mention it to the folks who handle those pages.

adafruit_support_mike
 
Posts: 61124
Joined: Thu Feb 11, 2010 2:51 pm

Re: MOSFET for Raspberry Pi

by axertion on Tue May 02, 2017 1:07 am

Thanks for the help Mike.

Can you see if I interpreted your schematic correctly? This is what I came up with, and it doesn't seem to be working :(

As I mentioned, I'm a complete beginner at this. This is literally my first Arduino/RPI project. The explanation as to why the MOSFET doesn't do as advertised is really confusing and frankly seems misleading to beginners that read things at face value!

Anyways, here's the circuit I put together while trying to follow your diagram. It's easier for me to visualize exactly what connects where so I can confirm everything is right!

MOSFET = TO-220 ESD (link)
NPN transistor = P2N2222A 741

Image
axertion
 
Posts: 11
Joined: Tue Nov 06, 2012 11:49 am

Re: MOSFET for Raspberry Pi

by axertion on Wed May 03, 2017 10:44 am

Ok, I got it working, however, it still only works with the 5v GPIO output.

3.3v still doesn't seem to work :(

I guess a better question is, are there any actual visual examples or best ways to control a 12V solenoid with the 3.3v GPIO pin on a Raspberry Pi?
axertion
 
Posts: 11
Joined: Tue Nov 06, 2012 11:49 am

Re: MOSFET for Raspberry Pi

by adafruit_support_mike on Thu May 04, 2017 3:51 am

Post a photo showing your actual hardware please. There are a couple of places where the connections and orientation of the parts make a difference.

adafruit_support_mike
 
Posts: 61124
Joined: Thu Feb 11, 2010 2:51 pm

Re: MOSFET for Raspberry Pi

by axertion on Fri May 05, 2017 9:49 am

Hi Mike, here's what I have so far. I have the GPIO replaced with the 3.3v pin on the Arduino UNO just for testing.

Thanks again for the help!

Image
Image
axertion
 
Posts: 11
Joined: Tue Nov 06, 2012 11:49 am

Re: MOSFET for Raspberry Pi

by adafruit_support_mike on Sat May 06, 2017 11:55 pm

It looks like your PN2222 is backwards.. emitter connected to the mosfet's gate, and collector connected to GND.

Try reversing that and see if it helps.

adafruit_support_mike
 
Posts: 61124
Joined: Thu Feb 11, 2010 2:51 pm

Re: MOSFET for Raspberry Pi

by zener on Sun May 07, 2017 1:17 am

Well, the OP stated P2N not PN and the pinouts are different (ask me how I know...) Maybe it is really a PN2222A

zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: MOSFET for Raspberry Pi

by adafruit_support_mike on Mon May 08, 2017 12:24 am

That's possible.. different transistors have different pinouts.

Post a link to the datasheet you're using and we'll take a look.

adafruit_support_mike
 
Posts: 61124
Joined: Thu Feb 11, 2010 2:51 pm

Re: MOSFET for Raspberry Pi

by axertion on Sun May 14, 2017 8:16 pm

I have it working now, thanks!

I have some more related questions due to the heat generated by using Mike's circuit.

1. When the Raspberry Pi is turned completely off, the 12V solenoid gets switched ON causing it to heat up (not ideal that it would stay on). I'm assuming this is because there's no current coming from the GPIO pinout to pull the MOSFET gate to off. Is there a way to prevent this? Ideally when Raspberry Pi 3.3v is ON, then the solenoid gets triggered.

2. When the Raspberry Pi is on and outputting the 3.3v from the GPIO, then the NPN transistor heats up a lot. To keep the solenoid off with Mike's circuit, I need the GPIO set to HIGH, which causes the 12v current to run through the NPN transistor, heating it up a lot.

So my main question, is there a way to build a circuit where the solenoid is OFF by default, and only triggered ON quickly when a 3.3v signal is detected?
axertion
 
Posts: 11
Joined: Tue Nov 06, 2012 11:49 am

Re: MOSFET for Raspberry Pi

by axertion on Thu May 18, 2017 5:55 pm

BUMP - any further assistance on this?

I'm kind of stuck on getting my project finished (and I'm sooo close). I really just want to trigger a push-pull type solenoid from a Raspberry PI 3.3V GPIO pin.

If someone could tell me the most appropriate and easiest way of doing this, I'd greatly appreciate it!

I don't mind ordering different parts, I just don't want to buy more things (AKA the MOSFET that I bought) and have it not work as advertised!
axertion
 
Posts: 11
Joined: Tue Nov 06, 2012 11:49 am

Re: MOSFET for Raspberry Pi

by zener on Fri May 19, 2017 12:28 am

I was going to let Mike work on his circuit. Yes there are ways to do what you want.

However, the NPN should not be getting hot so something is wrong there. With those two 10K resistors there is really no way for enough current to get through it to make any heat. Something is amiss.

zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: MOSFET for Raspberry Pi

by adafruit_support_mike on Fri May 19, 2017 2:43 am

Sorry for the delay.

To make the relay default to OFF, you just pull the 'turn off the thing that turns it off' trick one more time:

relay-2.jpg
relay-2.jpg (19.17 KiB) Viewed 2349 times
The mosfet all the way on the right is controlled by the NPN in the middle, which is controlled by the NPN on the left, and that's controlled by the RasPi.

If you work through the logic, the state of each item in the chain is the opposite of the one to its left:

- if the NPN on the left is on, the NPN in the middle will be off
- if the NPN on the left is off, the NPN in the middle will be on
- if the NPN in the middle is on, the mosfet will be off
- if the NPN in the middle is off, the mosfet will be on

We can simplify that by saying the activation pattern is either ON-OFF-ON or OFF-ON-OFF.

When the RasPi's output is high, the pattern will be ON-OFF-ON and the relay will close. When the RasPi's output is low (or there is no output), the pattern will be OFF-ON-OFF and the relay will open.

adafruit_support_mike
 
Posts: 61124
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.