dtown123
Posts: 6
Joined: Wed Jan 15, 2014 11:17 pm

rPi GPIO to Mosfet - won't fire relay coil

Wed Jan 15, 2014 11:26 pm

Hello -

I'm new to electronics so I have almost no idea what I'm doing. I hope you guys can help.

Basically I have two relays with 24VDC coils that I would like to be able to turn on via GPIO. If I connect the relay directly to ground, I can hear it "pop" which means the relay works. The schematic below is how I have it wired up. Via code I know the GPIO is working because I have replaced the relay with an LED and the LED lights up via code (that is not displayed, I use the green LED to show me that the decide is "Ready" by lighting up after boot)

I feel like I'm missing something very easy here. Any ideas? Thanks for your help! I hope this helps others eventually.
Image

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12672
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: rPi GPIO to Mosfet - won't fire relay coil

Wed Jan 15, 2014 11:37 pm

a few comments on your sketch.

You have no series resistor in series with your LED, that will damage the PI eventually. Put a 220 Ohm resistor in series.

You wire 3V3 to the breadboard. Why?

The most probably cause for the Mosfets not working is that they probably are not rated for the low 3.3V gate voltage, and need more (like 4 Volt) to go open. Choose a different type of FET, one that fully opens with a gate voltage as low as 3.0V.

dtown123
Posts: 6
Joined: Wed Jan 15, 2014 11:17 pm

Re: rPi GPIO to Mosfet - won't fire relay coil

Thu Jan 16, 2014 6:56 am

Looks like you were exactly right about the gate voltage. I got one of those step down DC devices with the rheostat and fired 4V to the gate and the relay popped right open. I then adjusted the output to 3.7V and put that on the gate. No "pop".

Might be a dumb question but does it have anything to do with the amount of voltage I'm attempting to ground (24V relay) when drain and source are connected?

I'm using Radio Shack IRF510. Any suggestions of a more appropriate FET N-channel with a gate that GPIO will trigger? Thanks!

obcd
Posts: 917
Joined: Sun Jul 29, 2012 9:06 pm

Re: rPi GPIO to Mosfet - won't fire relay coil

Thu Jan 16, 2014 2:58 pm

Have a look at npn darlington transistors like TIP120 instead of mosfets. You will need a resistor (1K)between your gpio output and the base of the darlington transistor. A darlington only needs 1.4 - 1.5V to conduct. It's current driven while mosfet gates are voltage driven. Due to the fact it's a darlington, the current amplification is very high, so you hardly need any current from the pi gpio's.
A mosfet can switch like 10 Amps. This current is much less with a darlington, but you don't need that for a relay.

dtown123
Posts: 6
Joined: Wed Jan 15, 2014 11:17 pm

Re: rPi GPIO to Mosfet - won't fire relay coil

Fri Jan 17, 2014 2:57 am

TIP120 with 1K resistor worked perfectly! Thanks for the "TIP"

Last question: What would be the best way to wire an LED in line with the TIP120 to light up with the "gate" is active? Thanks for your help guys! This has been really informative.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: rPi GPIO to Mosfet - won't fire relay coil

Fri Jan 17, 2014 4:31 am

These drawings showing the breadboard layout are almost impossible for me to read.

Here is the schematic of what I use to interface most high current (up to 60 amps) loads using a Mosfet.

In short, trying to source a positive voltage through a N channel Mosfet does not work.
Attachments
mosfet-schematic.JPG
mosfet-schematic.JPG (20.36 KiB) Viewed 4966 times
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

obcd
Posts: 917
Joined: Sun Jul 29, 2012 9:06 pm

Re: rPi GPIO to Mosfet - won't fire relay coil

Fri Jan 17, 2014 12:54 pm

You could connect the led with a decent serie resistor on the 24V relais voltage as well. Due to the high voltage drop over those resistors, they will heat up a little.
Assume you want 8mA passing trough your led.
R = 24 - 1.2 / 0.008 = 2850 Ohm
P = I * I * R = 0.008 * 0.008 * 2850 = 0.18W
So basically, a 0.25W resistor should still be fine.
A 2700 Ohm resistor is what you can easily find.
The led current will be a little higher with a 2700 Ohm resistor.

The 1.2V is the voltage standing on the led when approx. 8mA is passing trough it.
It depends upon the type of led and it's color, but is not that important in the equation.
8mA is an average current, enough for most leds to give decent light.

dtown123
Posts: 6
Joined: Wed Jan 15, 2014 11:17 pm

Re: rPi GPIO to Mosfet - won't fire relay coil

Mon Jan 27, 2014 5:28 am

Image
http://i.imgur.com/5Xub0aE.png

I hope this example isn't too difficult to tell what I'm trying to do. Basically I have a 24V relay that I'm controlling with the TIP120. I would like the same TIP120 to make a 5V LED light up when the relay is on.

Would this example work or blow something up? Any suggestions? Thanks again - it's fun learning this stuff.

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

Re: rPi GPIO to Mosfet - won't fire relay coil

Mon Jan 27, 2014 12:16 pm

Yes it'll work - but it'll blow up the LED ;)
5Xub.png
5Xub.png (3.22 KiB) Viewed 4841 times
If your LED is really a 5v one, then it has a series resistor built-in, so it'll survive so long as the transistor is on, but if it's just an ordinary one you'll need to put a resistor in series.

When the transistor is off, the LED will have about 19v across it in the wrong direction, and may blow up. Try putting a diode in series with it to take the strain.

dtown123
Posts: 6
Joined: Wed Jan 15, 2014 11:17 pm

Re: rPi GPIO to Mosfet - won't fire relay coil

Mon Jan 27, 2014 4:29 pm

I don't quite understand the diagram you made, so I re-did the diagram. I think it's what you described:
Image
http://i.imgur.com/mM3yLBM.png

Does this make sense? Thanks!

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

Re: rPi GPIO to Mosfet - won't fire relay coil

Mon Jan 27, 2014 5:10 pm

dtown123 wrote:I don't quite understand the diagram you made,
Well I did leave off all the labels - sorry, laziness I suppose
so I re-did the diagram. I think it's what you described:
(image)
Does this make sense? Thanks!
Exactly that!

Return to “Troubleshooting”