I am trying to make a variable motor control using one of an Arduino's PWM ports (and am pretty new to Arduino too). If the motor is going to be high-powered (let's just say 12v and a couple amps for now) how should I wire it? I've heard that MOSFETs may be useful, but I'm not sure. I've heard that MOSFETs don't perform too well at intermediate voltages.
Anyway, what I'm going for is making the motor speed controllable through a sketch that controls the output of that PWM port.
A logic level N-channel MOSFET is a very simple and practical way to control speed of a DC motor. A Arduino output pin can directly drive the gate of the MOSFET. It's a good idea to wire a pull down resistor from the gate to ground, and be sure to wire the 12vdc power's ground connection to the Arduino ground pin.
You pick the MOSFET specs to be well above the actual motor voltage and current. A heat sink may be required for the mosfet depending on how much current is being draw, but it is basically the most efficient way to control speed for a simple DC motor.
There are MOSFETS available for virtually all voltage and current ratings required.
If your using a 12volt supply and motor here is a nice MOSFET
Perfect. That should fully turn on at 5v, right? I just understood what PWM actually is - so the motor should be fed 12v, but the only thing that matters is the pulse width, right? It isn't actually creating a voltage from 0 to 5 volts; it's simply using 5v pulses that behave similar, is that right?
Yes, A logic level MOSFET will start to turn on around 1.5v or so and will be fully on (saturated) with a normal logic high level (around 4.5vdc or higher) that an Arduino I/O digital pin outputs. A non logic level N channel power MOSFET would require around 10v to be fully saturated.
It's just switching the 12vdc on and off to the motor at varying duty cycles. 0% is full off, just as if a digitalwrite command of zero was sent, the mosfet is totally off and the motor has no current flowing. 100% on the MOSFET is fully on and the motor will draw it's maximum rated current at the voltage you are supplying it with, just as if a digtalwrite command of one or on was sent. Any value between 0-100% (0-255 counts) will just be 5vdc pulses of varing lengths in a 0-255 step resolution. The induction of the motor winding is what converts this pulsating switching voltage to a steady state speed. It's magic.
The reason is works good is that high current mosfets have very low resistances when full turned off, in the milliohm range, and of course no current flows when the mosfet is driven off. So the only significant power (heat) loss is during the brief switching times as the square wave goes from 0 to 5vdc or 5vdc to 0.
This is in contrast with driving a transistor with a pure constant analog voltage value such that it's resistance is set to limit the current to the motor continuously for any given desired speed and as such acts like a power resistor that has to dissipate a lot of heat.
So bottom line is that logic level MOSFETs are now a days the easiest and best way to drive higher voltage or current loads that exceed what can be driven directly from an Arduino I/O pin.
How does this schematic look? The stuff connected to the MOSFET and the motor is to keep the voltage level at 12 volts (my batteries are 13.1 volts and the voltage drops as the motor runs). Could you check that as well? I kind of collaborated with a friend on it so it looks right to me, but I'm no electronic engineer. I added a snubber diode to prevent voltage spikes.
Well it's a bit odd. Its is not conventional and I am not sure what you are trying to do. Why a pulse transformer and logic driver? Why two FETs? Why connect the gate to -5V. Why all the dotted lines?
I think you should start again you seem to mix up AC and DC power supplies.
Well yikes. I will fix it up. Obviously my friend made the wrong suggestions to me. First schematic in Eagle, I had no idea how to use it, and my friend was talking me through it over the Internet
What I was going for was a circuit that should take the output of a 13.1 volt Ni-Cad battery and keep it at 12 volts so the speed of the motor doesn't drop as the battery discharges. How I should do that, I'm not sure. If the FET from the Arduino is connected wrong, then how should it be connected? I've never actually used one before.
e output of a 13.1 volt Ni-Cad battery and keep it at 12 volts so the speed of the motor doesn't drop
Do you mean that the output voltage must be 12V even when the battery drops below 12V? You can do this but it is a complex circuit to make and is not one for beginners. It is known as a buck / boost circuit. You can buy ready made modules but they are expensive.
Otherwise you need a series regulator these are simple and normally consist of one chip and a few capacitors. However the input voltage needs to be about 1V the output voltage for it to work so you don't have much scope for regulation here.
Oh, I see what I did wrong. I'm confused as to the layout of this circuit though. What do the positive and negative ends of my Ni-Cad battery connect to? I obviously know what the PWM port connects to, but how about the ground?
Ahh, the problem-solving capacity of the human brain.
I figured it out by experimenting with a 3 volt light bulb. It's much easier than I thought.
I wired the PWM port of the Arduino to the gate (1st pin) of my MOSFET. Then I wired the negative end of my 3 volt battery to the source (3rd pin) of the MOSFET. I used a resistor to pull down to the Arduino's ground. Then I wired the drain to one terminal of my light bulb and the other terminal of my light bulb to the positive end of my 3 volt battery.
I realize that if this were a motor I would have to wire a flyback diode in parallel with the motor to avoid EMF spikes. :o
To test it, I loaded up the sample fade program that comes with the Arduino software. Changed the PWM pin assignment and it works!
Here's a very low-quality image of the faded lamp (I didn't have time to get my good camera out so I used my webcam). The lamp and battery pack were originally out of one of those mini-flashlights that you get at restaurants.