How do electric motors work?
The short answer to this question is that electric motors convert electrical energy into magnetic energy, and then into rotational force. But it is clearly not that simple. An electric motor is the fundamental electro-mechanical energy converter that uses the forces of electricity, magnetism, angular momentum, and inertia, as well as electro-magnetic theory, Faradays theories of electric current, and Tesla's theories of alternating current. Now if that is not an impressive list, I don't know what is.
Magnets? I thought you use electricity?
You do, but electricity alone will not create rotation. The fundamental principle at work in an electric motor is magnetism. Imagine you have a paper clip on a table and you slowly move a magnet towards it. As the magnet comes close to the paper clip, one of two things will happen. The paper clip will either jump toward the magnet, sticking firmly, or it will slide away from the magnet until it gets far outside of its magnetic field. If you turn the magnet around in your hand, the opposite will happen. This is called the magnetic moment, and regardless of its shape, size or material, the magnet will always have a "pulling" force on one side and a "pushing" force on the other.
Now imagine replacing the paper clip with a magnet. What would happen if the "pushing" side of the magnet in your hand were pointed at the table magnet? Again, it depends on the orientation of the magnet on the table. If the same side of this magnet (the "pushing" side) were pointed at the magnet in your hand, the magnet on the table would slide away from you just as you would expect. However, if the magnet on the table had the "pulling" side pointed at the same "pushing" side of the magnet in your hand, the magnet would then jump off of the table and stick to the magnet in your hand. The point here is that by changing the polarity (or pushing/pulling side) of the magnet, you can change the direction that the magnet moves.
But how does that apply to motors?
A motor works exactly the same way, by controlling the orientations of the magnets inside it for a specific result. Inside of a motor, there are essentially four magnets. Two are on opposite sides of the outer casing (the stator), with one that is "pulling" and one that is "pushing." Two other magnets are on opposite sides of the spinning shaft; these switch between one "pulling" and one "pushing" at the same time.
The idea is that the one of the shaft magnets is set to "push" and the other to "pull," so they are pushed away from the closest stator magnet and pulled towards the next magnet. Just as they get to the halfway point between the two stator magnets, they switch to polarity and are attracted to the next stator magnets. At the exact second that the shaft magnets are closest to the stator magnets, they switch again and are then repelled by the closest magnet and attracted to the next, and continue to rotate. This happens forever as long as the mechanism exists to switch the polarity of the shaft magnets, which we will get to in a little bit.
But why does the shaft continue to spin in the same direction? Why doesn't it get stuck in the middle or spin the other way when the polarity changes?
The shaft continues to rotate in the same direction because of angular momentum and inertia. Inertia is the force that keeps you moving once you start, and what makes it difficult to start, if you are stopped. Imagine riding a bicycle. It is hard to start moving, easy to continue moving one you have started, and then hard to stop once you are going. Angular momentum is the force that makes a pendulum work, making a heavy thing on a string spin. As you rotate the object through the air on a string, it spins around your hand. When you stop moving your hand, the object continues to spin. It is because of this that the magnets on the shaft, called the armature, keep going in the same direction after they have started moving.
They don't get stuck because, well, real motors actually have three armature magnets and only two stator magnets, called permanent magnets. In this case, there is always an imbalance of magnetic force as two of the armature magnets pull toward one permanent magnet, while only one repels it. This guarantees that the motor never gets stuck on one position.
But what about that polarity switching mechanism and all this talk of electricity?
The magnets in the armature aren't exactly your standard type of magnets. These are called electromagnets and work by a principle of electro-magnetism that states that when electricity flows through a loop of wire, a magnetic field is generated. You can build one of these. You will need a non-magnetic screwdriver or iron nail, a battery, and some bare copper wire. Wrap the wire around the shaft of the nail a dozen or so times, then connect the ends of the wire to a battery. Your nail is now magnetic.
If you turn the battery around, you can see that your nail begins to repel metal objects. This is how the armature magnets work. A coil of wire is connected to the incoming power of the motor. As the power enters the loop, a magnetic field is generated for a moment in one direction. As the motor spins, the coil is disconnected from the power at the commutator and then reconnected backwards, thus creating the opposite polarity. This happens simultaneously with three coils of wire, some of which are connected forwards, and some backwards, creating rotation and a switching of the magnetic field.