Arduino N Channel Mosfet



The article elaborately explains how a mosfet or a BJT can be connected or interfaced with Arduino or any microcontroller in the most efficient and correct way. Cheap Motor Driver, Buy Quality Home Improvement Directly from China Suppliers:DC 5V 36V 15A 400W MOSFET Trigger Switch Drive Module PWM Regulator Control Panel for arduinoEnjoy ✓Free Shipping. 1000W Amplifier Circuit Famous Legend series 'Quasar' N-channel irfp240 MOSFET model 4-ohm speakers RMS with 1000w output power can give supply voltage.

High-Power Control: Arduino + N-Channel MOSFET

Eventually you are going to find yourself holding a 12v [[solenoid]], [[motor]], or light and wondering “How the heck am I supposed to control this from my Arduino?” And we have covered this in the past. Today we are going to talk about another way of doing just that, this time with an N-Channel MOSFET metal–oxide–semiconductor field-effect transistor, specifically the RFP30N06LE MOSFET (You can pick these up from sparkfun). but you can use any N-Channel MOSFET exactly the same way.

How this works

WARNING: I am about to simplify the crud out of this, so beware… it is here in an attempt to explain, in simple terms, what is going on.

First off, a MOSFET is a transistor, just a special kind.

If you don’t know transistors at all, they are 3 lead components that have 2 simple functions, to switch or amplify (in this example it is setup as a switch). You basically have an In called the Source, an Out called the Drain, and a Control called the Gate. When you send a HIGH signal to the gate (control pin), the transistor switches and allows current to flow from the source (in) to the drain (out).

So we connect it so that our motor, solenoid or light is connected to V+ but not ground (V-). Ground is connected to the transistor’s drain. When our arduino sends a HIGH signal to the transistor’s gate, it switches the transistor (connecting the drain and source) and completes the circuit for the motor, solenoid, or light.

More Information

If you want to know more, or actually know what is actually going on in there. Pete over at Sparkfun put out amazing video explaining MOSFETs for a solid 20min. Highly recommended.

Hooking it up / What’s the diode used for?

This circuit is pretty simple. The only part that looks funny is the resistor. This is a [[pull-down resistor]]. The resistor holds the gate low when the arduino does not send a high signal. This is here incase the arduino comes loose, or the wiring is bad it will default to off. You don’t want this pin to ever be floating as it will trigger on and off.

Mosfet

You can see that in 2 of the 3 illustrations, there is a [[diode]] parallel to the device we are powering. Any time you are powering a device with a [[coil]], such as a [[relay]], [[solenoid]], or [[motor]], you need this guy, and don’t leave home without it. What happens is when you stop powering the coil, a reverse [[voltage]], up to several hundred volts, spikes back. This only lasts a few microseconds, but it is enough to kill our MOSFET. So this [[diode]] (only allows current to pass one way) is normally facing the wrong direction and does nothing. But when that voltage spikes comes flowing the opposite direction, the diode allows it to flow back to the coil and not the [[transistor]]. We will need a diode fast enough to react to the kickback, and strong enough to take the load. A rectifier diode like the [[Diode Rectifier – 1A 50V |1N4001]] or SB560 should do the job. If you are looking for extra protection you could use an optoisolator between the Arduino and the transistor. An optoisolator optically isolates both sides (high and low power) of the circuit so the high-voltage can not possibly come back to the microcontroller.

Just make sure that protection [[diode]] is facing the correct way (stripe facing the V+ of device). If it is facing the wrong direction, the device you are trying to power will not work as the [[diode]] will just allow the current to bypass it.

Limitations

[[Transistors]] like the RFP30N06LE are really great for controlling high-power devices from your arduino, but they do have some limitations. This current configuration is only useful for switching [[DC]] current, so don’t try this with an [[AC]] source, also MOSFETS have both a [[voltage]] and an [[amperage]]/current limitation. The RFP30N06LE can handle switching up to 60V, and the amperage is limited to 30A (with heat sink and proper wiring). Anything over a few amps, especially when the current is constant (like in a motor) and not short pulses, I would recommend using a heat-sink. I usually just solder a bent pice of metal to the back, just something to help dissipate the heat. Just note, if you are using more than one of the RFP30N06LEs, you can not solder them to the same heat-sink as the back is connected to the drain of the MOSFET, not the source. If you need to switch AC, I would look at using a [[relay]] instead.

Arduino Controlling N Channel Mosfet

Fade it!

You know the [[PWM]] outputs on your Arduino? Yeah, the thing that allows you to analogWrite(pin, value). Well, [[PWM]] is not actually an [[analog]] output. The Arduino is actually pulsing (very quickly) between 0 and 5v so that the average [[voltage]] is somewhere in between 0 and 5. Because of this, the [[PWM]] can be extended through the [[transistor]] (the transistor can only turn on or off, but can do so very quickly) allowing us to fade lights or control the speed of a motor just like if they were connected directly to the Arduino. All you need to do in order to take advantage of this is make sure the MOSFET’s gate is connected to a [[PWM]] pin.

Code

You don’t really need code for this, you just send a HIGH signal to the gate pin, and BAM… it works. But I threw this together for you so you can test it fading with the PWM- This code fades in a sin wave like the video below. (only useful for a motor or light obviously).

[code lang=”arduino”]
//////////////////////////////////////////////////////////////////
//©2011 bildr
//Released under the MIT License – Please reuse change and share
//Simple code to output a PWM sine wave signal on pin 9
//////////////////////////////////////////////////////////////////

#define fadePin 3

void setup(){
pinMode(fadePin, OUTPUT);
}

void loop(){

for(int i = 0; i<360; i++){ //convert 0-360 angle to radian (needed for sin function) float rad = DEG_TO_RAD * i; //calculate sin of angle as number between 0 and 255 int sinOut = constrain((sin(rad) * 128) + 128, 0, 255); analogWrite(fadePin, sinOut); delay(15); } }[/code]

Arduino N Channel Mosfet

Video

This video is showing the capabilities of PWM with the RFP30N06LE. The light, though it looks like a standard house light, is actually a 15W 12V DC light.

No Comments

Introduction: How to Control a MOSFET With Arduino PWM

In this instructable we'll look at how to control the current through a MOSFET using an Arduino PWM (Pulse Width Modulation) output signal.

In this case we'll manipulate the arduino code to give us a variable PWM signal on digital pin 9 of the arduino, and we'll then filter this signal to give us an adjustable DC level which can be applied to the gate of the MOSFET.

This will allow us to control the transistor from an off state with no current flowing to a state where only a few milliamps of current flow or to a state where we have several amps of current flowing through the transistor.

Here I'll set up the PWM so that we have 8192 steps of pulse width variation which give us very fine control over the MOSFET.

Step 1: Circuit Diagram

The circuit is very straightforward. The PWM signal from pin D9 of the arduino is integrated or filtered by the combination of R1 and C1. The values shown work well an operating frequency of 1.95KHz or 13 bit operation with 8192 steps (2 to the power 13 = 8192).

If you decide to use a different number of steps then you may need to change the R1 and C1 values. For example if you use 256 steps (8 bit operation) the PWM frequency will be 62.45 KHz you will need to use a different C1 value. I found 1000uF worked well for this frequency.

From the practical point of view a PWM setting of 0 means that the DC level on the MOSFET gate will be 0V and the MOSFET will be completely turned off. A PWM setting of 8191 will mean that the DC level on the MOSFET gate will be 5V and the MOSFET will be substantially if not completely turned on.

The resistor R2 is in place just to ensure that the MOSFET turns off when the signal on the gate is removed by pulling the gate to ground.

Provided that the power source is capable of supplying the current dictated by the PWM signal on the MOSFET gate, you can connect it directly to the MOSFET with no series resistor to limit the current. The current will be limited by the MOSFET only and it will dissipate any excess power as heat. Be sure that you provide an an adequate heat sink if using this for higher currents.

Attachments

Step 2: Arduino Code

The arduino code is attached. The code is well commented and fairly simple. The block of code on lines 11 to 15 sets up the arduino for fast PWM operation with output on pin D9. To change the PWM level you change the value of compare register OCR1A. To change the number of PWM steps you change the value of ICR1. e.g 255 for 8 bit, 1023 for 10 bit, 8191 for 13 bit operation. Be aware that as you change ICR1 the frequency of operation changes.

The loop just reads the state of two pushbutton switches and increments the OCR1A value up or down. I've preset this value in the setup() to 3240 which is just below the value where the MOSFET starts to turn on. If you use a different transistor or C1 & R1 filter circuit this value will be slightly different for you. Best to start with the preset value at zero the first time you try this just in case!

Step 3: Test Results

With ICR1 set to 8191 these are the results I obtained varying the current between 0 and 2 AMPS:


OCR1A (PWM SettingCurrent (ma)Gate Voltage (Vdc)
3240 0 ma 0v
3458 10ma 1.949v
4059 100ma 2.274v
4532 200ma 2.552v
4950 500ma 2.786v
5514 1000ma 3.101v
6177 1500ma 3.472v
6927 2000ma 3.895v

Be the First to Share

Recommendations

2.1 Bluetooth Sound System - Fully Printable in Audio
3 Ways to Make Cardboard PinBall Sensors in Sensors
23 8.2K
211 15K

N Channel Mosfet Circuit

  • STEM Contest

  • Role Playing Game Challenge

  • CNC Contest





Comments are closed.