theitguyfromny
Posts: 21
Joined: Fri Jan 11, 2019 4:42 pm

Resistors and MOSFETs and fire-prevention, oh my

Sat Feb 02, 2019 2:36 pm

* Note: This is not a problem, it's a question beforehand so I don't have a problem.

I have:

1) a RPi 3B+
2) a RFP30N06LE 30A 60V N-Channel Power Mosfet. I bought it from Amazon but I think this is a valid spec sheet...https://www.sparkfun.com/datasheets/Com ... 0N06LE.pdf
3) a 1/4inch DC 12V 2 Way Normally Closed Electric Solenoid Air Valve.

Just for a "non-computerized" test of the solenoid, I simply plugged in a 12V (1.5A) power supply and when the wires were connected, it snapped back exactly as I'd expect and need. Works perfect!

The plan here is to simply control this with my RPi/MOSFET. My question is, From what I read, I think I need at least 1 resistor somewhere. If so, where, what size, and (and I'll probably be able to figure this out if someone answers those 2 Qs), why?

Generally, I understand I will connect the positive wire of the solenoid directly to the power source. Negative from power supply will go on the SOURCE (middle pin of MOSFET) and a wire will go from right side pin of MOSFET to the solenoid. The gate pin will connect to a GPIO pin [that I will do wonderfully magical things with that is top secret, lol]. So, I think I have all that right...but...do I need 1 or 2 or 84 resistors in that mix?

Thanks for the help, all!

User avatar
Burngate
Posts: 5967
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Resistors and MOSFETs and fire-prevention, oh my

Sat Feb 02, 2019 7:08 pm

A couple of things.

You're labelling the pins of the MOSFET as middle = Source, right, and gate.
But the datasheet you linked to has two drawings - TO-220AB & TO-263AB - neither of which has the source in the middle, so I'm confused.

From your description, I think you have:

Code: Select all

               _________ +12V
               |
               |
               |
              ---
              | |
              | | solenoid
              | |
              ---
               |
               |
               | drain
            -------
            |     |
GPIO -------|     |
       gate |     |
            -------
               | source
               |
Pi GND         |
_______________________-12v
Note: the Pi's GND, the source of the MOSFET and the 12v negative are joined together.

You can put a resistor in the GPIO - gate line; that will help protect the Pi if you connect things wrongly.
You can also connect a resistor between the gate and source, to hold the gate low and the solenoid off, while the Pi's booting (the GPIOs are configured as inputs until you make them different; the gate could float high and do nasty things to either mosfet or Pi)

Brandon92
Posts: 773
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Resistors and MOSFETs and fire-prevention, oh my

Sat Feb 02, 2019 8:55 pm

I would also add a diode across the solenoid to protect the MOSFET. And a gate resistor is also not a bad idea.

@Burngate
What for kind of program are you using for those diagram?

theitguyfromny
Posts: 21
Joined: Fri Jan 11, 2019 4:42 pm

Re: Resistors and MOSFETs and fire-prevention, oh my

Sat Feb 02, 2019 8:58 pm

Thanks. The question, though, is what size resistor.

As far as a diode, same q: where, and...what size?

User avatar
Burngate
Posts: 5967
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Resistors and MOSFETs and fire-prevention, oh my

Sun Feb 03, 2019 10:02 am

The resistor between GPIO and gate: large enough that current from the GPIO is lower than it can handle.
Since the GPIO can't provide more than ~15mA and 3v3, Ohms law says more than 220 ohms. 1k would be enough. So would 470 or 330, depending on what you have in your bits-box.

For the resistor from gate to source: doesn't really matter, but 10k would be good.
Because the two resistors will form a potential divider, and you want the gate to go as high as possible, using 1k and 10k for those would give 3v at the gate. 330 and 3k3 would do the same, while 330 and 33k would take it closer to 3v3.

The diode (that Brandon92 remembered but I forgot - sorry!) needs to be able to handle the 12v that'll be across the solenoid when it's on, and whatever current the solenoid is taking at the moment the FET switches off.

@Brandon92
Notepad, on my Windows laptop.
I know, I know, Raspberry Pi is Linux-based, and I shouldn't allow Windows anywhere near here, but I don't care!
And Notepad is clutzy for drawings, but it works.
For more complicated or prettier pictures I fire up RiscOs, 'cos I've been using it since whenever and I'm happy with it.
Other people use things like Fritzing. One day I'll learn how to use that - just not today.

Brandon92
Posts: 773
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Resistors and MOSFETs and fire-prevention, oh my

Sun Feb 03, 2019 11:52 am

@Burngate
A okay, I thought that you where using a program that generated that. But notepad is indeed usable for this task. And I'm also using Windows :?

To give you a little bit on why this gate resistor is needed. As you might know you can turn in a MOSFET with a certain voltage. Rather than a current with a transistor. So, why is the resistor needed Then? Well this is because the gate has also some (parasitic) capacitance. And when you want to turn on the MOSFET, that capacitor need to be charged and the Rpi will see it as a "short" circuit for a small amount of time. And the gate resistor will limit the current to a save value for the Rpi.

A general diode will to the job here. Like the 1n4148 and if the solenoid is bigger a 1n4007 will do. You need to connect the cathode to the 12v and the anode to the drain.

User avatar
davidcoton
Posts: 4008
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Resistors and MOSFETs and fire-prevention, oh my

Sun Feb 03, 2019 11:53 am

Burngate wrote:
Sun Feb 03, 2019 10:02 am
The diode (that Brandon92 remembered but I forgot - sorry!) needs to be able to handle the 12v that'll be across the solenoid when it's on, and whatever current the solenoid is taking at the moment the FET switches off.
Remember too that diodes are polarised -- it needs to go across the coil in the direction that does NOT conduct the normal 12V supply. The aim is to provide a short path for the "back EMF" produced by a coil (such as in a solenoid) when it is turned OFF --the current will try to continue as the magnetic field decays, which can produce a damaging reversed voltage if not removed by the diode.

(Posting anyway though Brandon92 got here first.)
Signature retired

theitguyfromny
Posts: 21
Joined: Fri Jan 11, 2019 4:42 pm

Re: Resistors and MOSFETs and fire-prevention, oh my

Sun Feb 03, 2019 5:58 pm

Thanks so much.

So, right now I have:

Code: Select all

-------------- 
|            |
|            |
|            |
|            |
 ------------      
  |   |   |
  |   |   |       
  |   |   |       
 (G) (D) (S)     
G is Gate: goes to GPIO pin (P.S....that is set to OUT mode) with a 1K resistor in-line (resistors are NOT direction-specific)
D is Drain: goes to solenoid
S is source: goes to negative of power supply
Note: Positive of power supply is going directly to solenoid.
I still do not know where the diode goes exactly, so that's my only remaining question, as long as I have everything else good to go.
I DID find out that, unlike resistors, diodes ARE direction-specific and for the one I have (A 1N4001) the light grey stripe goes TOWARDS the supply); this one also supports up to 50V, so I'm way more than covered there.

User avatar
rpdom
Posts: 14984
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Resistors and MOSFETs and fire-prevention, oh my

Sun Feb 03, 2019 6:09 pm

theitguyfromny wrote:
Sun Feb 03, 2019 5:58 pm
Thanks so much.

So, right now I have:

Code: Select all

-------------- 
|            |
|            |
|            |
|            |
 ------------      
  |   |   |
  |   |   |       
  |   |   |       
 (G) (D) (S)     
G is Gate: goes to GPIO pin (P.S....that is set to OUT mode) with a 1K resistor in-line (resistors are NOT direction-specific)
D is Drain: goes to solenoid
S is source: goes to negative of power supply
Note: Positive of power supply is going directly to solenoid.
I still do not know where the diode goes exactly, so that's my only remaining question, as long as I have everything else good to go.
I DID find out that, unlike resistors, diodes ARE direction-specific and for the one I have (A 1N4001) the light grey stripe goes TOWARDS the supply); this one also supports up to 50V, so I'm way more than covered there.
All correct.

The diode goes across the solenoid connections. Stripe to power supply positive as you said, other end to the connection between the solenoid and the Drain.

The stripe is the Negative side of the diode (the Cathode). When the solenoid is powered on the diode will not pass electricity as it is connected in reverse to the solenoid (as it should be). When power to the solenoid is turned off the magnetic field in it generates a spike of electricity in the opposite direction to the normal flow. The diode will shunt that power safely out of the way. A 1N4001 should be fine for that circuit.

User avatar
PeterO
Posts: 4940
Joined: Sun Jul 22, 2012 4:14 pm

Re: Resistors and MOSFETs and fire-prevention, oh my

Sun Feb 03, 2019 6:28 pm

Burngate wrote:
Sun Feb 03, 2019 10:02 am
The resistor between GPIO and gate: large enough that current from the GPIO is lower than it can handle.
It's a MOSFET, so gate current will be very small until you hit the gate protection diodes (at +10V and -8V from the data sheet) so you can use a larger gate resistor. The only change will be a slightly increased turn-on and turn-off times as the gate capacitance (1350pF from data sheet) will take longer to charge/discharge.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

danjperron
Posts: 3390
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Resistors and MOSFETs and fire-prevention, oh my

Sun Feb 03, 2019 6:38 pm

Capture d’écran 2019-02-03 à 13.37.19.png
schematic example
Capture d’écran 2019-02-03 à 13.37.19.png (44.76 KiB) Viewed 1681 times

Brandon92
Posts: 773
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Resistors and MOSFETs and fire-prevention, oh my

Sun Feb 03, 2019 9:16 pm

PeterO wrote:
Sun Feb 03, 2019 6:28 pm
It's a MOSFET, so gate current will be very small until you hit the gate protection diodes (at +10V and -8V from the data sheet) so you can use a larger gate resistor. The only change will be a slightly increased turn-on and turn-off times as the gate capacitance (1350pF from data sheet) will take longer to charge/discharge.

PeterO
Yes, when the MOSFET is in a steady state. The current is very small. But, that is not the case when you turn it on or off. Like I explained couple post back.

If we take a look at the datasheet of the SoC, we can see that the rise time of the digital output is around 1.6ns (page 12). Let assume that this Rpi is ideal and the MOSFET only is made out of the input capacitor (Ciss). Then the current can rise to 2.8A to charge the input capacitor! As showed in simulation below. And a gate resistor will protect the output of the SoC, so that the current is in a save range. And when the MOSFET is turned off, that energy is present in the input capacitor will be dissipated in the Rpi also.
Attachments
MosfetGateCurrent.PNG
MosfetGateCurrent.PNG (31.8 KiB) Viewed 1657 times

User avatar
PeterO
Posts: 4940
Joined: Sun Jul 22, 2012 4:14 pm

Re: Resistors and MOSFETs and fire-prevention, oh my

Sun Feb 03, 2019 9:42 pm

Your analysis is flawed.
Brandon92 wrote:
Sun Feb 03, 2019 9:16 pm
If we take a look at the datasheet of the SoC, we can see that the rise time of the digital output is around 1.6ns (page 12).
That's only true for an unloaded GPIO pin. Assuming the GPIO is ideal is nonsense, and leads to nonsense results like it supplying 2.8A to charge the 1350pf to 3.3V in 1.6nS. That just isn't going to happen ! :roll:
The GPIO pin is a voltage source which has a maximum source current as well, so you can easily workout a realistic rise time (it will be much longer that 1.6nS).

If sufficient resistance is added between the GPIO pin and the gate, such that the peak current is less than the upper limit, then the GPIO pin can be modelled as a simple voltage source making rise/fall time calculations even easier as it's a simple RC circuit driven from a voltage source.

PeterO
BSc. Electronic Engineering.
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
Burngate
Posts: 5967
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Resistors and MOSFETs and fire-prevention, oh my

Mon Feb 04, 2019 12:00 pm

danjperron wrote:
Sun Feb 03, 2019 6:38 pm
Capture d’écran 2019-02-03 à 13.37.19.png
Just a note: This diagram is far nicer than mine, and better than any I've seen done in Fritzing.
So it might be worth asking what program he's using

danjperron
Posts: 3390
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Resistors and MOSFETs and fire-prevention, oh my

Mon Feb 04, 2019 12:13 pm

I do own a Orcad license and a free version of Eagle but it is Fritzing! In schematic mode. ;-)

I just did a screen save from my Mac.

theitguyfromny
Posts: 21
Joined: Fri Jan 11, 2019 4:42 pm

Re: Resistors and MOSFETs and fire-prevention, oh my

Mon Feb 04, 2019 1:15 pm

Finally got a chance to test this morning (everyone back to work now, Mu haha) and...I guess the good news is all my connections are solid.

Bad news is I can't get the solenoid to power up.

Just for a test, I've tapped the wires directly to the solenoid and it clicks over (just to make sure there's no solenoid issues still). Good to go there.

I'm not getting the power from the gate to toggle it. I'm still confused exactly how much power is required into this gate to toggle it? I feel like I'm saying this wrong despite the million times I've read about plumbing analogies...but, when I turn on the GPIO pin (set it to HIGH...gpio -1 write 12 1)...I am changing it's current from 0 to about 3.3V (for this particular GPIO.1 pin, anyway; the RPI is NOT sending it power...amps, it's just allowing for amps. I think I'm wrong, though.

My reading talks about 2 types of gates: Standard Gates require some specific threshold of amperage to be met (a spec that is different per exact FET model) in order to toggle it;Logic-Level Gates, though, will toggle with any voltage/amperage change coming in to the gate...so, because I want to control this Gate with my RPi, I bought a Logic-Level Gate (because I'm not coming anywhere near 12V with my RPi, of course).

...but, then, why can't I toggle power?


So excited to have this piece of the puzzle working...and thank you all very much!

danjperron
Posts: 3390
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Resistors and MOSFETs and fire-prevention, oh my

Mon Feb 04, 2019 3:22 pm

First Test if you put 3.3v directly to the resistor, is the mosfet activate?. (remove the gpio pin).

Is the drain voltage lower on the mosfet? if yes what is the voltage.

If the 3.3V works at the mosfet then it is time to check if your GPIO toggle. Use a led with a resistor to limit the current and check if it works,


Mosfet gate use very low current but they have a big capacitance effect to counteract.


Could you please provide to us a picture of your settings which will show all your connections?

theitguyfromny
Posts: 21
Joined: Fri Jan 11, 2019 4:42 pm

Re: Resistors and MOSFETs and fire-prevention, oh my

Mon Feb 04, 2019 3:55 pm

OK, so first test you suggest: I disconnected the gate wire from the GPIO pin (the ONLY pin I had connected) and tapped it - instead - against the always-on 3.3V GPIO pin...and still got no activity.

I think what I'm missing is the GND on the GPIO. Don't I need to connect 2 pins to the RPi? a POS AND a NEG?

I could take pics, but when I just thought about it, the only thing that would really do is confirm soldering work, which is not the problem. I have a multimeter and, although I don't know how to do much with it, I tested continuity.

Gate on left is the wire I'm interfacing with the RPi (above test), Drain in center goes out to negative wire of solenoid, and source on right goes to negative on power supply.

danjperron
Posts: 3390
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Resistors and MOSFETs and fire-prevention, oh my

Mon Feb 04, 2019 4:02 pm

I think what I'm missing is the GND on the GPIO. Don't I need to connect 2 pins to the RPi? a POS AND a NEG?
Of course the ground of the Pi needs to be connected to the ground of your 12V supply which is your source of your mosfet.
You need to close the loop!!!

This is also true for the GPIO.

if 3.3V doesn't work try to put 5V on your gate instead.

Still waiting for the picture.

theitguyfromny
Posts: 21
Joined: Fri Jan 11, 2019 4:42 pm

Re: Resistors and MOSFETs and fire-prevention, oh my

Mon Feb 04, 2019 4:32 pm

So sorry about the NEG to GPIO thing. If you look back, I'm not sure anyone ever said that, all the triple-confirming I did...

First: Here's the photo:
FET.jpg
FET.jpg (107.27 KiB) Viewed 1536 times
The yellow wire, the GATE, I had connected to the GPIO. Your test just now had me tapping it on the 3.3V on the RPi.
The middle white wire, the DRAIN, I have going to the negative on solenoid.
The right-side black WAS going ONLY to the neg on the power supply.

Note: I now have the black wire going to BOTH the negative on the power supply AND a GND port on the RPi (I've T'd it). On that note, rpdom noted that,
The diode goes across the solenoid connections. Stripe to power supply positive as you said, other end to the connection between the solenoid and the Drain.
. Is that before the T to the RPi, I assume?

Especially now that I had the NEG NOT connected to the Rpi, I still feel like I'm simply doing some obvious thing wrong, because I know how to eliminate variables in testing and I've now tested with 2 different FETs, and the solenoid all by itself works fine.

All that siad, here's what's happening now:

When I tap the gate wire on the GPIO's 3.3V pin WITH the resistor (tried a 10K and a 1K), there is NO CHANGE.
When I tap the gate wire on the GPIO's 3.#V pin WITHOUT a resistor, the solenoid activates!...but it only does this one time. (after removing the gate wire from the 3.3V pin and re-tapping it (by the way, what's the electrical term for this quick connection? there must be a term), I get no result. I can then unplug the power supply, wait 10, 15 seconds, and THEN it reacts as before again. I'm believing this has something to do with that diode, but I obviously want to have repeated control of all this through software, so..something still awry.

Thanks again; while priceless to me right now, this communication method obviously has its' imperfections. :-/

danjperron
Posts: 3390
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Resistors and MOSFETs and fire-prevention, oh my

Mon Feb 04, 2019 5:26 pm

Thanks but what I was expected the connection between the mosfet (view of the raspberry Pi) and the view of your selenoid.


First you should check if your mosfet behave like it is suppose to do.


No Raspberry Pi needed.

Please check your mosfet with a voltmeter. If you put the red wire to P1 the voltmeter should display a lower voltage. Not connected it should be the power voltage. Use your 12V or a 9V battery. For 12V don't use it on the gate because it is over the maximum voltage. Just add another 10K in series.
mosfetTest.png
Mosfet test
mosfetTest.png (130.12 KiB) Viewed 1519 times

theitguyfromny
Posts: 21
Joined: Fri Jan 11, 2019 4:42 pm

Re: Resistors and MOSFETs and fire-prevention, oh my

Mon Feb 04, 2019 6:21 pm

Works as you describe.

NOT connected: About .20 (voltmeter set to DCV 20)
CONNECTED: .10/.09

danjperron
Posts: 3390
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Resistors and MOSFETs and fire-prevention, oh my

Mon Feb 04, 2019 6:31 pm

NOT connected: About .20 (voltmeter set to DCV 20)
CONNECTED: .10/.09
It's not working then. The mosfet not connected should give you ~20V and not 0.2V.

Did you put a resistor load on the drain like I did on the schema?
Do you have another mosfet on hand?

theitguyfromny
Posts: 21
Joined: Fri Jan 11, 2019 4:42 pm

Re: Resistors and MOSFETs and fire-prevention, oh my

Mon Feb 04, 2019 6:39 pm

I don't know the voltmeter, but doesn't the decimal location of that # just have to do with the setting on the voltmeter? (20 versus 200, vs, 1000, etc)?
multimeter.jpg
multimeter.jpg (244.94 KiB) Viewed 1492 times

theitguyfromny
Posts: 21
Joined: Fri Jan 11, 2019 4:42 pm

Re: Resistors and MOSFETs and fire-prevention, oh my

Mon Feb 04, 2019 6:52 pm

Here's a link to photo of labeled set-up.

https://drive.google.com/file/d/1adAPr8 ... sp=sharing

Hope that works (was too large file size to post )

Again, right now, it works perfect...once. Then I have to unplug it, wait a bit, plug it back it again, works again...once.

Return to “Beginners”