# How to drive this MOSFET with a microcontroller?

I'm trying to drive a motor with a 7V battery pack using the 5V pinout from a microcontroller. The pinout is connected to the gate pin of an IRF510 MOSFET.

This is my current circuit:

The simulation clearly works fine, but when I make the circuit the motor keeps turning when pinout is 0V, only more slowly. I recorded these voltages:

Voltage across motor when pinout is ON: 6.55V (this is fine)
Voltage across motor when pinout is OFF: 5.77V (should be 0V, I want it to stop)

The current through the motor is 0.2A regardless of voltage, but the drop in voltage when the pinout goes off obviously causes the motor to slow down a bit.

I've tried tying the gate to ground (ground pin of the microcontroller) with a 20k resistor, but this had no effect. If I understand it correctly, I only need to worry about a transient voltage when the microcontroller itself is physically switched off? I'm also not sure if I should use the ground of the microcontroller or the ground of the 7V battery pack (all the diagrams I've seen use a common ground).

• You state that you've tried tying the gate to the microcontroller ground. Is the microcontroller ground connected to the FET source (so that you are influencing Vgs)? – HikeOnPast Aug 2 '12 at 0:07
• Do you have the microcontroller ground and the battery negative terminal tied together? – Oli Glaser Aug 2 '12 at 1:27
• No, the microcontroller and battery grounds are not connected. Should my circuit look like this? i.imgur.com/Q2qJE.png (don't want to make it until you guys confirm, incase I damage my microcontroller) – Matt Aug 2 '12 at 10:30
• @Matt - Yes, grounds should definitely be connected, otherwise the FET's gate voltage has no relationship with the source's. Your schematic is fine. – stevenvh Aug 2 '12 at 12:51
• @Matt If you're concerned about damaging the uC (which is not unwise), test the circuit without the uC first. – Nick Alexeev Aug 2 '12 at 16:54

Be SURE that you are implementing this circuit.
Diode is needed (1N400x will do to start for motors under a few amps)

The MOSFET you are using is marginal for use with 5V gate drive.
A "logic FET" with a lower gate turn on voltage will be better.

The action you describe indicates either that the MOSFET is dead or connected wrongly.

The above circuit diagram is modified from fig 8. here
This is a useful page that will teach you things that you want and need to know.

• Instead of a logic level FET a mosfet driver chip could be used, for instance a TC4427. – Wouter van Ooijen Aug 2 '12 at 8:55
• So should my circuit look like this? i.imgur.com/Q2qJE.png What component does the diode protect, the microcontroller, MOSFET or battery pack? – Matt Aug 2 '12 at 10:28
• @Matt - Yes, but it's more common to draw the +7 V at the top, and the motor above the FET, like in Russell's schematic. The diode protects the MOSFET. If the motor is switched off it will create a possibly high voltage on the drain which may destroy the FET. The diode allows current to flow to the battery's +, and so avoids a voltage build-up. – stevenvh Aug 2 '12 at 12:49
• @Matt I was going to comment about the readability of the schematic too. Read this post by Olin (it's a white paper, really). There are certain conventions. If they are followed, the schematic becomes more readable. For example, the questions like "is it a low- or a high-side switch?" can be answered by inspection. – Nick Alexeev Aug 2 '12 at 16:51

If you look closely at the principle drawing of the MOSFET in the IRF510 datasheet, you'll notice a diode between drain and source (in parallel to the MOSFET itself). It's called power MOSFET's body diode.

Body diode is what's conducting the current, when you drive the gate with 0V. Notice in the O.P. that the voltage difference between ON and OFF voltages is 0.78V, which is close to the forward voltage drop of the silicon diode.

You simulation assumes an ideal MOSFET without a body diode, probably.

The body diode should be reverse-biased, if you want to be able to switch off the current. So, source should be connected to the negative side.

• This made perfect sense, until I realised that my actual circuit is reverse-biased - the MOSFETS in the diagrams I uploaded are the wrong way around. I'm sure you're on to something with this diode though because its behaviour seems to be slightly dependent on some other factor like room temperature. I rechecked my circuit and source is definitely connected to negative. – Matt Aug 1 '12 at 22:50
• @Matt - if your grounds are not connected it may be capacitive effects you are seeing, since if the MOSFET is actually connected the right way the body diode won't cause any problems. If you can e.g. touch the FET gate with your finger and the motor changes speed then the problem is that the gate is floating (i.e. not pulled to 0V properly) You need a reverse biased diode across the motor too (see Russell's answer) to protect against inductive kickback. – Oli Glaser Aug 2 '12 at 5:47
• The grounds are not connected, and touching gate does indeed cause the motor to change speed. Is this the correct circuit? i.imgur.com/Q2qJE.png – Matt Aug 2 '12 at 10:32