Introduction: Tutorial:DC Motors-1/3: Continuous, H-Bridge, Gear

I believe I have made this Instructable easy to understand. However, we do discuss a variety of motor styles so if after reading this you have any questions, please feel free to get in touch with me directly. You can contact me at (Please replace the second 'i' with an 'e' to contact me. Thank you.)

If you do find this article helpful, even if it is relative to when you see it some months or years old, please be kind enough to mouse click "Favorited" at the top of this Instructable. Your support is appreciated.

DC motors are ubiquitous. They convert electrical/magnetic energy, produced by a wire carrying current in a magnetic field, to motion, and they appear in all sorts of appliances and applications, e.g., they are found in small fans, ceiling fans, air cleaners, solder fume extractors, quadcopters, small helicopters, and other drones, hand-held rotary tools, circular saws, drills, lathes, sanders, cars, robots (where they rotate tires, or move robotic arms, etc.), aquarium air pumps, maker projects, and many other areas. The most popular motors generally have shafts that are round, or 'D'-shaped (i.e., flattened on one side), flattened on two sides, or geared (i.e., have gears directly cut into the shaft or mounted on the shaft). See photographs for examples of these popular shaft styles. Although motors can run from DC, AC, and in the case of universal motors from both DC and AC, this tutorial only discusses DC motors in detail.

Electric current and magnetism go hand-in-hand as it is impossible to have one without the other. As can be seen in the photographs current through a wire moves a compass needle owing to the magnetic field generated around the wire by the current passing through it. Hans Christian Oersted, the Danish physicist, identified this connection between electricity and magnetism in the early 1800's. [Some interesting but not essential information: The 'Oe' in the name shown here, can be replaced by a single capital Danish O (i.e., Ø) and on occasion one sees his name as Ørsted].

Magnetism produced by current flowing through a single wire is weak. If this wire is wound into a coil the magnetic field becomes stronger. If this coil is then wrapped around a ferrite core its magnetic field becomes even stronger.

The theory of DC motors is not too difficult to understand, if we recall that for magnets opposite poles attract and similar poles repeal. A DC motor works by having the poles of a rotor through which current flows, thereby producing a magnetic field, subjected to another magnetic field which attracts the magnetic field of the rotor. It is interesting to learn that the opposite is also true. That is, as a motor rotates the interaction of the magnetic fields produces a voltage. This can be seen in the video above where a NEMA-17 stepper motor is turned to produce a voltage and light an LED, i.e., where the motor is used as a generator.

In this tutorial we will discuss several types of DC motors: continuous DC motors, gear Motors, DC servo motors, brushless DC motors, coreless DC motors, vibration motors, and DC stepper motors, although there are many other types of motors, these are probably the most popular with Arduino users.

Motors are devices that can impart motion, i.e., movement, to our projects. You can see two of my prior Instructables where this occurs: “Personal, portable, lightweight, air conditioner: An inexpensive and effective DIY project”, and “Making a Hypnotic disk using an Arduino and small DC motor”. They provide examples of DC motors that were used in Arduino projects. Some other Arduino projects using motors are BlackStar Vvek’s, “Arduino based humanoid robot using servo motors”, “Arduino + K'nex Motors” by link2_thepast, martinbolton’s “Arduino+Stepper Motor Camera Slider”, etc. In fact, many Instructables can be found that use an Arduino and one or more motors.

Fortunately, with DC motors used by Makers, we need not be too concerned with voltage (although we need to be sure a motor is designed to work at the voltage we have available) or current (although we need to be sure we have a switch that will handle the current the motor takes, as motors usually take more current than is available, e.g., from an Arduino digital or analog pin).

Our main concerns with motors are speed and torque. Speed for motors is measured, unlike it is when we measure the speed of a car in miles per hour or kilometers per hour, in rotations per minute (RPM) or radians/sec, e.g., 3,000 RPM or 450 rad/sec. Note these are but two examples of how motor speed might be represented. They are not meant to imply that 3,000 RPM is equal to 450 rad/sec; it is not. Fortunately, it is easy to covert from RPM to radians/sec or degrees/sec or the reverse. Speed is represented by the Greek letter omega, ω.

Sir Isaac Newton's second law of motion is: Force equals mass multiplied by Acceleration, where Force and Acceleration are directional, although mass is not. Torque is a "twisting/turning force". Force is frequently measured in Newton (N), and when we multiply force by length we get torque, e.g., Newton-meters (N-m), Newton-centimeters (N-cm), or ounce-inches (oz-in).

In a motor the torque is always tangent to a circle centered on the shaft, i.e., it is at a right angle to a diameter. The symbol designating torque is the lowercase Greek letter tau, τ, and less frequently the English capital letter T. Datasheets for DC motors usually provide speed in both RPM, and radians or degrees/sec.

Torque is often presented in datasheets in several forms (e.g., as peak torque, stall torque (more on this later), and rated torque, etc. DC motor datasheets are usually quite comprehensive and present other motor parameters as well. It should be noted that motors can have the same power capability, but different speed and torque, as it is possible to exchange speed for torque (for more on this see gear motors below). Mass and weight are not the same. Although they are often interchanged in informal conversations. For example, on the moon a motor would have the same mass it does on Earth, but its weight would be different.

Step 1: Continuous Motors

There are four main parts to many continuous brushed DC motors. The rotor (the part that rotates) or armature (in engineering speak the armature is the component of an assembly that turns/pivots and that holds the main current carrying coils that produce a magnetic field) here the rotor and armature are the same, i.e., they are both the turning component in the center.

The stator, as its name might suggest, is stationary, it provides the magnetic field that surrounds the rotor (it is often in two parts if the stator is made from a permanent magnet). If so, the stator magnets are known as field magnets. Field magnets are reliable, as the magnetic field remains at a constant level, although their fields may diminish with time. Permanent magnets are found in many brushed motors. If the stator is made from an electromagnet the coils used to produce this magnetic field are known as field windings or field coils. The remaining two parts of a typical brushed motor are the commutator, and the brushes/contacts.

Some decades ago DC motors used actual copper "brushes" that were held by springs and pressed against the commutator to shift current to the coils and keep the motors turning. Today DC motors have contacts that "brush" against the commutator, but true brushes are uncommon. Although actual brushes are not common, these devices are still referred to as brushed motors. Brushed motors are inexpensive, and usually have operational lives that are longer than the devices they are part of.

However, brushless motors are also available today, as noted previously, and seem to be trending upward as brushes/contacts can wear out, and may produce sparking. Brushed motors, as noted, are less expensive to manufacture and are commonly used in Maker projects. However, it is important to learn if their rotors rotate in bushings or ball bearings, as bushings have a shorter operational live. There will be more on brushless motors later in this tutorial.

In a simple DC motor the armature connects to a DC power source to produce a magnetic field when current flows. However, when the armature moves orthogonal to the stator, i.e., at right angles to the stator's magnetic field, there is almost no torque experienced. The momentum of the rotor usually carries it forward to continue spinning. To overcome this ‘defect’, a second armature coil at right angles to the first is added so that there is always one segment of the armature that is exposed to a higher magnetic torque, i.e., is receiving power while the rotor is in a stronger portion of the magnetic field of the stator.

In most working DC motors (see attached photographs) there are several armature coils offset from each other. In general, the more windings a coil has the higher its resistance, and the greater its torque, but the slower its speed. These coils insure that the motor turns smoothly and always yields a high torque at all points in its rotation. The rotor is connected to a commutator, which is a component that allows the rotor coil to change polarity as required to rotate continuously. The commutator is usually just a simple cylinder with contacts that have insulating gaps between them to allow "brush" conductive elements to connect, in turn, to the DC power source (see attached photographs). That is, it provides a simple switch to change the DC input. The commutator is connected to the DC power source by contacts that "brush" against the contacts on the commutator.

Permanent magnet stators are used in many small DC motors, an example of which can be seen in the attached photographs. In other small DC motors and many larger DC motors the stator is magnetized by the same power source as the rotor. This can occur in one of two ways: parallel (producing a shunt motor) or serial producing a series motor. The stator can be connected to the DC power source in series or in parallel with the armature/rotor.

There is a space between the rotor and stator, so as to allow the rotor to turn easily. This space is referred to as the "air gap" between the two. Most motors are rotary, but there are motors where the rotary motion is converted to linear motion. These devices are known as "linear motors" or "linear actuators (although actuators may get their energy from sources other than DC)". Most motors used in Maker projects are fractional horsepower (FHP), as they have a rating less than one horsepower.

See the pictures here of the disassembled small continuous DC motor. The two permanent magnets that make up the stator, the rotor/armature, and the coils can be easily seen in the attached photographs of the this motor.

Step 2: An Arduino Project Using a Continuous Motor

A continuous DC motor usually requires more amperage than the maximum 40ma, 20ma is best, current available using an analog or digital Arduino pin. This restriction is not a problem when using an LED, but is a problem when using a DC motor. To overcome this limitation, a 2N2222 transistor was used here, these can be obtained for less than $0.20 each. They work well as switches, and in the project presented here, the 2N2222 easily switches the required motor current on and off. A datasheet for this transistor, can be found at e.g.,

This datasheet notes that the maximum voltage between emitter and base should not exceed 6.0 V, So, be sure to keep your voltage below this maximum value, or you risk damaging the transistor.

The attached picture is of a 2N2222 in the less expensive TO-92 package rather than the original metal TO-18 package. In this configuration the 2N2222 / 2N2222A is also called a P2N2222 or PN2222A. It is important to review the datasheet for the particular version of this transistor that you use, to ensure that the maximum acceptable voltages and currents from base to emitter, and collector to emitter, are not exceeded.

An alternative choice would be a MOSFET. We could also use a mechanical device such as a relay, or if you do not need to drive it from an Arduino a simple switch. If you need to handle more power then the 2N2222 can safely dissipate, a TIP120, darlington complementary, transistor will work. If properly heat sinked it can handle as much as 5A. For still more amperage, a TO-220 packaged N-Channel RFP30N06LE (P30NO6LE, P30N06) MOSFET can handle somewhat over 30 amps when its drain flange is appropriately connected to a metal heat sink. This N-Channel MOSFET can be driven from an Arduino, and is useful for large DC motors.

The higher current flows between the 2N2222’s collector and emitter pins and is controlled by the base and emitter pins. For this NPN transistor, when the base pin is set to turn the transistor on, as in this project, the transistor switch allows more current to flow between the collector and emitter pins of the 2N2222 than flows between its base and emitter. A 1N4001 diode was placed across the two pins of the motor, with the line on the diode facing the positive voltage. It is placed in the opposite direction to normal current flow, and so usually has no current passing through it. The 1N4001 is used as a flyback diode to offer a path for the energy produced by the collapsing magnetic field of the motor when the power is shutoff. It is hard to place the diode incorrectly without knowing it, as if configured this way it will shunt the current to the motor and the motor will not spin.

Although this may only occur for a few microseconds, it can produce quite high voltage, in the range of 100s of volts, enough to damage the transistor. All DC motors work in an essentially similar manner. So, when using these with an Arduino, a transistor, BJP or MOSFET, or relay, etc., a switch that can handle the extra current needed by the motor is required, and likely a user-added flyback diode.

Fortunately, the 5v pin of the Arduino can provide about 450ma from USB and slightly more if the barrel jack is used, perhaps as much as 650ma. The 5v pin and ground were used to power the continuous motor used in the sketch presented in the next Step.

Step 3: Sketch for the Arduino Project Using a Continuous Motor

In an early part of the sketch’s loop function, the continuous DC motor is turned on for 5 seconds (5000 milliseconds). A HIGH signal, i.e., 5v, is sent to the motor. [The motor used here takes less current than can be provided by the Arduino's 5v power supply. However, if the motor you are using takes more current, a power supply separate from that available on the Arduino will be needed.] After the motor is run for 5 seconds, it is gradually slowed down to a complete stop using digital pin 6, which can process pulse width modulation (PWM) signals.

Here the motor turns in one direction. The speed of the motor is slowed down using a PWM signal starting at 255 and decreasing in increments of 3 until it reaches 0. The use of PWM allows us to mimic voltages between 0 and 5v. At some point the simulated voltage to the motor is too low to turn the motor, i.e., the PWM duty cycle is too low to activate the motor. For this example that approximate point is when the duty cycle reaches 30. At this point in the sketch, the LED is turned off, as the motor is not spinning. A propeller, rather than a twisted wire, was connected to the motor here, as it allows us to easily see the action a balanced motor as it turns, as it provides better balance to the motor than an asymmetric wire would. However, if you do not have a propeller, a twisted wire would yield related results. However, if you only have a wire that cannot be balanced on both sides of the shaft, you should likely read Part 2 of this tutorial that contains a Step on vibration motors, as an unbalanced load on the motor is likely to cause it to vibrate.

A red LED (just visible in the video) is turned on and faded to completely off in concert with the speed of the motor. This is accomplished in 30 lines of code as can be seen here.

To see the sketch exactly as written please download the text file.


// Run a motor at full speed then continuously reduce its speed until
it is off.

// Fade an LED in consonance with the motor's speed

int motorInputPin = 6;

int ledPin = 10;

int delay2 = 5000;

int delay3 = 50;

void setup() {

pinMode(motorInputPin, OUTPUT);

pinMode(ledPin, OUTPUT);


void loop() {

// Turn motor on for delay2/1000 seconds

digitalWrite(ledPin, HIGH);

digitalWrite(motorInputPin, HIGH);


// Continuously slow motor down

for (int i = 255; i >= 1; i = i - 2) {

analogWrite(motorInputPin, i);

analogWrite(ledPin, i);

// Delay delay3/1000 seconds between changes in motor speed



// Pause for delay2/1000 seconds



Step 4: H Bridge, Motor Direction Reversal

No presentation of DC motors would be complete without a mention of H Bridges. The theory behind an H Bridge is quite simple, and easy to understand. It gets its name from the configuration of its main components: 4 switching elements and a DC motor that can be diagrammed in the configuration of the capital letter ‘H’ (see photograph above).

Its operation is straightforward, if S1 and S4 are closed while S2 and S3 stay open the current flows through the motor in one direction from + to ground. If S2 and S3 are closed while S1 and S4 are open the current flows through the motor in the opposite direction from + to ground. (See attached photograph). The illustration here shows the switching elements as normally open switches, i.e., mechanical devices. Notice that these switches need to be closed in a particular fashion. If for example either switch pairs S1 and S3 or S2 and S4 were closed at the same time this would provide a short circuit path between the positive voltage and ground. Closing S1 and S2 while leaving S3 and S4 open will have no effect as S1 and S2 are connected to the same positive voltage and so no current will flow. The situation is similar if we close S3 and S4 at the same time while leaving S1 and S2 open, in this situation S3 and S4 are both connected to ground. If current is not running through the motor, as when switch S1 and S2 are closed and S3 and S4 are open or vice versa, the motor will stop.

The switching elements could just as well be relays, another mechanical element, or solid state devices such as bipolar junction transistors (BJTs), or metal oxide semiconductor field effect transistors (MOSFETs). In most modern H Bridges the switching elements are solid state devices, usually MOSFETS. The advantages of MOSFETs over BJT is that they can switch current to large loads while needing only a small amount of current to switch on. In practice diodes are placed across each switching element, with the lines on the diodes facing the positive voltage. This is done so that when e.g. all switches are open after the motor has been running, the current generated by the motor, due to its collapsing magnetic field, has a path to take. However, rather than use discrete components, e.g., switches, relays, BJTs, or MOSFETs, most H Bridge board makers use integrated circuits (ICs), such as the board based on the L298 IC shown above.

If you use an H Bridge module with your own Arduino sketch, it is probably an excellent idea to open all switching elements before changing direction, as this will insure a short circuit is not created even momentarily.

H Bridges are found in power inverters, robots, motor controllers, etc. They are frequently used to drive a stepper motor

Step 5: DC Gear Motors

Most continuous DC motors typically run at 1,000s of revolutions per minute (RPMs). Gear motors are often used to reduce RPMs (speeds) to less than 1,000, and one can easily find gear motors with RPMs of less than 100. They use, as the name would imply, an assemblage of gears, a reduction gear train, to obtain this reduced speed. In general, the more the reduction the slower the speed. DC gear motors come in a myriad of speeds, shapes, and sizes. They are hard not to enjoy.

An excellent example of the need for a gear motor is a timepiece, such as an analog wristwatch. The motor in a wristwatch needs to provide rotations at slow speeds. For example, the second-hand rotates at only one RPM. Another example are the tires in a robot car, which also must rotate at relatively slow speeds. While the main motor, in a gear motor, may rotate at over 1,000 RPM, reduction gears allow for a much slower rotation of the output. Gear motors can provide significant torque are low RPMs. In fact, torque increases as speed slows. In general, the higher the current the higher the torque. Gear motors are found in automobiles, clocks, washing machines, drills, kitchen mixers, and in industrial equipment such as cranes, jacks, winches, conveyor belts, etc. They can change direction (just swap the leads to the motor), spin at different speeds, and stop quickly. They are often found in robots, e.g., robot cars. A word of caution: efforts to run a motor above or below its voltage range can damage the motor. If the motor will not turn the voltage is likely too low, and if it feels hot to the touch the voltage is probably too high. Gear motors can often be identified as their rotating shafts are often not aligned with the center of the main motor, to provide room for the gears, but not always (see photographs).

As voltage increases the speed of the motor typically increases (see attached video). One of the videos shown here is for a DC gear motor where the voltage ranges from 2-17 volts. The higher the voltage the faster the gear motor's rotation. The voltage first goes from low to high and then back to low.

The second video shows the slow speeds possible using a gear motor even with some minor changes in input voltage. The last video is of a 12v gear motor run at less than 12v, so it runs somewhat slower than it would at a full 12v.

Step 6: Afterwards

If you have come to this point congratulations. You should now have a basic understanding of some of the key elements of the DC motors covered in this Part. I hope you found Part 1 of this Instructable interesting and of value.

If you liked this Part of the tutorial you may want to continue on by reading Part 2 at,

It may be obvious, that this tutorial, even though it is in three parts, just "scratches the surface" of DC motors. Each of the motors covered here could have its own multi-part tutorial, or perhaps an entire textbook.

If you have any comments, suggestions, or questions related to this Part of the tutorial, please be kind enough to add your comments below, to those already received.

If you have any thoughts or questions, related to DC motors in general, but not covered in this tutorial, or any suggestions for how I could improve this or the other Parts of the tutorial, I would be pleased to hear from you. You can contact me at (Please replace the second 'i' with an 'e' to contact me. Thank you.)