Driving Bigger Loads (Motors, Lamps, and the Like)

Each of the pins on an Arduino board can only be used to power devices that use a very small amount of current, such as an LED. If you try to drive something big like a motor or an incandescent lamp, the pin might stop working, and could permanently damage the microcontroller that is the heart of your Arduino.

WARNING

To be safe, the current going through an Arduino’s I/O pin should be limited to 20 milliamps.

Don’t worry, though. There are a number of simple techniques that allow you to control devices that use much more current. The trick is a bit like using a lever and fulcrum to lift a very heavy load. By putting a long stick under a big stone and a fulcrum in the right place, you can pull down on the long end of the stick, and the short end, under the stone, has much more force. You pull with a small force, and the mechanics of the lever apply a larger force to the stone.

In electronics, one way to do this is with a MOSFET. A MOSFET is an electronic switch that can be controlled by a small current, but in turn can control a much larger current. A MOSFET has three pins. You can think of a MOSFET as a switch between two of its pins (the drain and source), which is controlled by a third pin (the gate). It is a little like a light switch, where the gate is represented by the part you move to turn the light on and off. A light switch is mechanical, so it is controlled by a finger, but a MOSFET is electronic, so it is controlled by a pin from your Arduino.

NOTE

MOSFET means “metal-oxide-semiconductor field-effect transistor”. It’s a special type of transistor that operates on the field-effect principle. This means that electricity will flow though a piece of semiconductor material (between the drain and source pins) when a voltage is applied to the gate pin. As the gate is insulated from the rest through a layer of metal oxide, no current flows from Arduino into the MOSFET, making it very simple to interface. MOSFETs are ideal for switching on and off large loads at high frequencies.

In Figure 5-7, you can see how you would use a MOSFET like the IRF520 to turn on and off a motor attached to a fan. In this circuit, the motor actually takes its power from the VIN connector on the Arduino board, which is intended for a voltage between 7 and 12 volts. This is another benefit of the MOSFET: it allows us to control devices that need a different voltage from the 5 V used by Arduino.

The black component with the white band around it is a diode, and in this circuit it’s being used to protect the MOSFET.

Conveniently, MOSFETs can be turned on and off very quickly, so you can still use PWM to control a lamp or a motor via a MOSFET. In Figure 5-7, the MOSFET is connected to pin 9, so you can use analogWrite() to control the speed of the motor through PWM. (Remember that only pins 3, 5, 6, 9, 10, and 11 can be used with analogWrite().

To build the circuit, you will need an IRF520 MOSFET and an 1N4007 diode. If the motor randomly turns on during upload, place a 10 K ohm resistor between pin 9 and GND3.

Learn about a relay, which is another way to control devices that use more current.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *