Direct Current Motors



    • Introduce the direct current motors.
    • Understand the operation basis.
    • Assemble a typical circuit to use and control a DC motor.
    • Assemble a variable speed drive.



Bill of materials

Arduino Uno Arduino UNO or equivalent.
Jumper wires
A breadboard plus some jumper wires.
330 Ohm Resistor

A 330 Ohm resistor.

Red LED  A LED diode.
Potentiometer  A 10k potentiometer.
DC motor with wheel

DC fan

A direct current motor.

We are going to use a wheel to show how it spins.




It is difficult to move through our world without stumbling over electric motors of all types and sizes. From the little ones with which you start the car every morning to the very little ones that move the CD or DVD player, to those which turns the microwave oven’s turntable with which you heat the coffee when getting up, we are surrounded by electric motors.

We can buy from large high power three-phase alternating current motors for industrial jobs to small DC motors to move the wheels of a small remote control car.

In previous chapters, we have already discussed how to control servos or small DC motors, but it is time to devote a little more time and detail to seeing what they are and how to use them in our Arduino projects.
And as always is preferable to start from the beginning, we are going to start with the DC motors and seeing how we can control them.

I’m sure you’ll all be familiar with the fact that all magnets have one positive and one negative pole and that while opposite poles attract, same poles repel each other.

Magnet poles

There is a very close relationship between the current intensity and the magnetic fields, defined by Maxwell’s equations and it turns out that when we run a current through a conductor that is immersed in a magnetic field, it is subjected to a electromotive force that we can use as the basic principle of operation of an electric motor.

From a practical point of view, if we run a current through a wire that is between the poles of a magnet, a mechanical force will appear that will oppose the changes of this current and try to turn the conductor to compensate them.

The force that appears will be proportional to the intensity of the magnetic field, and to the number of conductors that are crossed by the current, (what we do is to wind copper turns around a core to make a winding, so that the force increases).

All electric motors have two basic parts:

  • The stator or stationary part that usually is built by using either fixed magnets or by a generating a variable field by using alternating current (which would lead us to build an AC motor, of course)
  • The rotor, in which are put turns of copper wire or windings around a core, so that the force exerted on the rotor multiplies proportionally to the number of turns.


As the electromotive force rotates the rotor a fraction of a turn, finally we would find that we would reach a position of equilibrium, which would not suit us at all because it would stop the rotation of the motor.

That is why we have to complicate the matter a little more and make sure that we have multiple windings in different positions, so that when one winding reaches equilibrium the other takes over and keeps the motor spinning.

Ilustra el giro del motor

Look at the black blocks marked + and – (that are called brushes) that are kept static while we fed with electric current a pair of turns with opposite windings. When they reach equilibrium, that set of turns is turned off and the brushes feed the next set of turns for a fraction of a turn … and it starts over again.

Thus there is always a set of conductive turns outside the equilibrium position which is subjected to the electromotive force and forces the engine to rotate looking for a balance (as in the case of magnets) that we never let it reach.

Little DC motor
Esquema interior

In the image on the left you can appreciate the windings of conductive wire, for a small DC motor. In the animation on the right, you can see the whole set spinning. The shaft is the axis of rotation, brushes are brushes, of course, rotor coils are the conductive wire windings and magnets are magnets.




In the chapter about transistors, we saw that it was very easy to make a small motor spin by means of a transistor that regulates the current intensity that we delivered to it.

In that chapter we focused almost exclusively on the transistor, to introduce this component (which we will use again and again), and practically we used the dc motor as an excuse without entering the subject. But this time we want to focus on the little DC motor and how can we control it. That’s why we are going to return to this example, but complicating it a bit more, adding a potentiometer that will allow us to vary the speed of rotation of the motor.

For this we will use a 5V DC motor, with a wheel, which you can find for very little money and besides it is useful to appreciate the spin.

Like any motor, however small, it consumes more than whichever of the pins of our Arduinos can provide, so we need to use a transistor like the 2N2222 to power it. And we will use one of the Arduino pins to control this transistor.

We will repeat the assembly that we saw in the chapter about transistors with this little DC motor. We include a the wiring diagram and the transistor pin-out we used there.

Transistor gobernando un motor



2N222 Transistor

Here you have the initial wiring schematic without the potentiometer so that you can check the connections of the motor and test whether it works correctly, before going ahead.

DC motors wiring diagram


To check that the motor works, you can upload this small sketch, which simply varies the voltage that we apply in the pin 9 to modify the speed of rotation of the motor:

const int control = 9 ;

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

void loop()
        for ( int n = 0 ; n < 255 ; n++)
              analogWrite (control,  n) ;
              delay(15) ;

As you will see, it simply puts an analog value on pin 9. We can control the motor speed by varying the voltage we apply in the base of the transistor, since this regulates the resistance that the transistor presents between emitter and collector.

At 0V the transistor goes into cut-off region (infinite resistance) and at 5V it is in saturation, thus presenting zero resistance.

  • Do not assume that we can make the motor rotate continuously for all voltage values applied to the base. Below a certain threshold it will stop and will only rotate when it is exceeded.
  • By increasing the voltage value we apply to the motor, the speed of rotation will increase progressively.  

Let’s now try to place a potentiometer connected to the analog gate A1. Its reading will be used to vary the signal that we put in the base of the transistor, so varying the speed of rotation.

The idea is that as we increase or decrease the voltage at the base of the transistor, the voltage drop varies accordingly causing the motor to receive more or less voltage, translating this into a change of its speed of rotation.

The following sketch reads the potentiometer and varies the speed of rotation accordingly:

const int control = 9 ;

void setup()
  {    pinMode(control,  OUTPUT) ;

void loop()
       int n = analogRead(A1)/ 4;     // The analog readings go up to 1024, not up to 255
       analogWrite (control,  n) ;
       delay(200) ;

Thus, controlling a small DC motor is quite easy, but … so far the motor always rotates in the same direction. How can we make it to reverse its direction of rotation?

This, dear friends, will be the matter of the next chapter, because for that we will need to improve the circuit a little more.




    • We have seen the foundations of direct current motors.
    • We have reviewed a typical control circuit.
    • We have seen that the rotational speed is proportional to the voltage applied to the motor terminals.
    • We have seen how to vary the speed using this idea.






No Comments

Give a Reply